Skip to content

Commit

Permalink
[CORE]Update api design
Browse files Browse the repository at this point in the history
Merge pull request #409 from annuaire-entreprises-data-gouv-fr/update-api-design
  • Loading branch information
HAEKADI authored Sep 2, 2024
2 parents 769957c + c1c243f commit 4e3f980
Show file tree
Hide file tree
Showing 70 changed files with 270 additions and 269 deletions.
3 changes: 0 additions & 3 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
ELASTIC_USER = os.getenv("ELASTIC_USER")
ELASTIC_URL = os.getenv("ELASTIC_URL")
DSN_SENTRY = os.getenv("DSN_SENTRY")

# Other configuration constants
CURRENT_ENV = os.getenv("CURRENT_ENV", "dev")
APM_URL = os.getenv("APM_URL")
BASE_DIR = pathlib.Path(__file__).parent
OPEN_API_PATH = BASE_DIR / "doc" / "open-api.yml"


# Elastic APM configuration
APM_CONFIG = {
"SERVICE_NAME": "SEARCH APM",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from app.request.search_params_model import SearchParams
from app.request.search_type import SearchType
from app.controller.search_params_model import SearchParams
from app.service.search_type import SearchType


class SearchParamsBuilder:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

from pydantic import BaseModel, field_validator, model_validator

from app.request.field_values import (
from app.controller.field_validation import (
FIELD_LENGTHS,
NUMERIC_FIELD_LIMITS,
VALID_ADMIN_FIELDS_TO_SELECT,
VALID_FIELD_VALUES,
VALID_FIELDS_TO_SELECT,
)
from app.request.helpers import (
from app.utils.helpers import (
check_params_are_none_except_excluded,
clean_str,
match_bool_to_insee_value,
Expand Down
2 changes: 1 addition & 1 deletion app/decorators/http_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sentry_sdk import capture_exception, push_scope

from app.exceptions.siren import InvalidSirenError
from app.response.helpers import serialize_error_text
from app.utils.helpers import serialize_error_text


def http_exception_handler(func):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import logging
from datetime import timedelta

from app.request.search_type import SearchType
from app.response.helpers import is_dev_env
from app.search.es_index import StructureMapping
from app.search.geo_search import build_es_search_geo_query
from app.search.helpers.helpers import (
from app.elastic.es_index import StructureMapping
from app.elastic.geo_search import build_es_search_geo_query
from app.elastic.helpers.helpers import (
execute_and_agg_total_results_by_identifiant,
extract_ul_and_etab_from_es_response,
page_through_results,
)
from app.search.text_search import build_es_search_text_query
from app.elastic.text_search import build_es_search_text_query
from app.service.search_type import SearchType
from app.utils.cache import cache_strategy
from app.utils.helpers import is_dev_env

TIME_TO_LIVE = timedelta(days=31)
MIN_EXECUTION_TIME = 400
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from elasticsearch_dsl import Q

from app.search.helpers.elastic_fields import get_elasticsearch_field_name
from app.elastic.helpers.elastic_fields import get_elasticsearch_field_name


def filter_search_by_bool_fields_unite_legale(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from app.search.helpers.elastic_fields import get_elasticsearch_field_name
from app.elastic.helpers.elastic_fields import get_elasticsearch_field_name


def build_etablissements_filters(search_params):
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from app.search.helpers.elastic_fields import get_elasticsearch_field_name
from app.elastic.helpers.elastic_fields import get_elasticsearch_field_name


def filter_term_search_unite_legale(
Expand Down
4 changes: 2 additions & 2 deletions app/search/geo_search.py → app/elastic/geo_search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from elasticsearch_dsl import Q

from app.search.filters.term_filters import filter_term_list_search_unite_legale
from app.search.helpers.exclude_etablissements import (
from app.elastic.filters.term_filters import filter_term_list_search_unite_legale
from app.elastic.helpers.exclude_etablissements import (
exclude_etablissements_from_search,
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def exclude_etablissements_from_search(es_search_builder): #
def exclude_etablissements_from_search(es_search_builder):
# By default, exclude etablissements list from response
include_etablissements = (
es_search_builder.search_params.include_admin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from app.search.parsers.siren import is_siren
from app.elastic.parsers.siren import is_siren


def extract_ul_and_etab_from_es_response(structure):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from elasticsearch_dsl import query

from app.search.helpers.elastic_fields import get_elasticsearch_field_name
from app.elastic.helpers.elastic_fields import get_elasticsearch_field_name


def search_bilan(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from app.search.es_search_runner import ElasticSearchRunner
from app.search.filters.siren import filter_by_siren
from app.elastic.es_search_runner import ElasticSearchRunner
from app.elastic.filters.siren import filter_by_siren


def search_index_by_siren(siren: str):
Expand Down
File renamed without changes.
30 changes: 15 additions & 15 deletions app/search/text_search.py → app/elastic/text_search.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
from elasticsearch_dsl import Q

from app.search.filters.boolean import (
from app.elastic.filters.boolean import (
filter_search_by_bool_fields_unite_legale,
)
from app.search.filters.id import filter_by_id
from app.search.filters.nested_etablissements_filters import (
from app.elastic.filters.id import filter_by_id
from app.elastic.filters.nested_etablissements_filters import (
add_nested_etablissements_filters_to_text_query,
build_nested_etablissements_filters_query,
)
from app.search.filters.siren import filter_by_siren
from app.search.filters.siret import filter_by_siret
from app.search.filters.term_filters import (
from app.elastic.filters.siren import filter_by_siren
from app.elastic.filters.siret import filter_by_siret
from app.elastic.filters.term_filters import (
filter_term_list_search_unite_legale,
filter_term_search_unite_legale,
)
from app.search.helpers.bilan_filters_used import is_any_bilan_filter_used
from app.search.helpers.etablissements_filters_used import (
from app.elastic.helpers.bilan_filters_used import is_any_bilan_filter_used
from app.elastic.helpers.etablissements_filters_used import (
is_any_etablissement_filter_used,
)
from app.search.helpers.exclude_etablissements import (
from app.elastic.helpers.exclude_etablissements import (
exclude_etablissements_from_search,
)
from app.search.helpers.helpers import (
from app.elastic.helpers.helpers import (
get_doc_id_from_page,
should_get_doc_by_id,
sort_search_by_company_size,
)
from app.search.parsers.siren import is_siren
from app.search.parsers.siret import is_siret
from app.search.queries.bilan import search_bilan
from app.search.queries.person import search_person
from app.search.queries.text import build_text_query
from app.elastic.parsers.siren import is_siren
from app.elastic.parsers.siret import is_siret
from app.elastic.queries.bilan import search_bilan
from app.elastic.queries.person import search_person
from app.elastic.queries.text import build_text_query


def build_es_search_text_query(es_search_builder):
Expand Down
7 changes: 4 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
OPEN_API_PATH,
)
from app.logging import setup_logging, setup_sentry
from app.router import router
from app.routers import admin, public

# Setup logging
setup_logging()
Expand Down Expand Up @@ -53,5 +53,6 @@ def custom_openapi():
app.add_middleware(ElasticAPM, client=apm_client)
setup_sentry()

# Include the router
app.include_router(router)
# Include routers
app.include_router(public.router)
app.include_router(admin.router)
File renamed without changes.
2 changes: 1 addition & 1 deletion app/response/response_model.py → app/models/response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel, RootModel

from app.response.unite_legale_model import UniteLegaleResponse
from app.models.unite_legale import UniteLegaleResponse


class ResponseModel(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from app.response.format_search_results import format_search_results
from app.response.helpers import is_dev_env
from app.response.response_model import ResponseModel
from app.models.response import ResponseModel
from app.service.format_search_results import format_search_results
from app.utils.helpers import is_dev_env


class ResponseBuilder:
Expand Down
File renamed without changes.
30 changes: 0 additions & 30 deletions app/request/helpers.py

This file was deleted.

111 changes: 0 additions & 111 deletions app/response/helpers.py

This file was deleted.

Binary file not shown.
Loading

0 comments on commit 4e3f980

Please sign in to comment.