From a4b2cedf063c547aa8acfe70667400b0f624e556 Mon Sep 17 00:00:00 2001 From: Hugo Lecuyer Date: Mon, 28 Oct 2024 17:03:54 +0100 Subject: [PATCH] wip --- ...3f_add_profils_autres_field_in_service.py} | 12 ++++----- .../api/inclusion_data/routes.py | 20 +++++++-------- .../api/inclusion_data/services.py | 25 +++++++++++++------ 3 files changed, 33 insertions(+), 24 deletions(-) rename api/src/alembic/versions/{20241017_105705_9bb9919e6b83_add_profils_autres_field_in_service.py => 20241028_172223_c947102bb23f_add_profils_autres_field_in_service.py} (81%) diff --git a/api/src/alembic/versions/20241017_105705_9bb9919e6b83_add_profils_autres_field_in_service.py b/api/src/alembic/versions/20241028_172223_c947102bb23f_add_profils_autres_field_in_service.py similarity index 81% rename from api/src/alembic/versions/20241017_105705_9bb9919e6b83_add_profils_autres_field_in_service.py rename to api/src/alembic/versions/20241028_172223_c947102bb23f_add_profils_autres_field_in_service.py index edab24a7..0391e158 100644 --- a/api/src/alembic/versions/20241017_105705_9bb9919e6b83_add_profils_autres_field_in_service.py +++ b/api/src/alembic/versions/20241028_172223_c947102bb23f_add_profils_autres_field_in_service.py @@ -1,8 +1,8 @@ -"""add profils_precisions field in service +"""add profils_autres field in service -Revision ID: 9bb9919e6b83 -Revises: e3f3dfa4ad01 -Create Date: 2024-10-17 10:57:05.985264 +Revision ID: c947102bb23f +Revises: 68fe052dc63c +Create Date: 2024-10-28 17:22:23.374004 """ @@ -10,8 +10,8 @@ from alembic import op # revision identifiers, used by Alembic. -revision = "9bb9919e6b83" -down_revision = "e3f3dfa4ad01" +revision = "c947102bb23f" +down_revision = "68fe052dc63c" branch_labels = None depends_on = None diff --git a/api/src/data_inclusion/api/inclusion_data/routes.py b/api/src/data_inclusion/api/inclusion_data/routes.py index 37c4f369..f09677c2 100644 --- a/api/src/data_inclusion/api/inclusion_data/routes.py +++ b/api/src/data_inclusion/api/inclusion_data/routes.py @@ -214,15 +214,6 @@ def list_services_endpoint( """ ), ] = None, - profils_precisions: Annotated[ - Optional[str], - fastapi.Query( - description="""Une recherche elargie sur les profils. - Chaque résultat renvoyé correspond a la recherche fulltext sur - ce champs. - """ - ), - ] = None, modes_accueil: Annotated[ Optional[list[di_schema.ModeAccueil]], fastapi.Query( @@ -276,7 +267,6 @@ def list_services_endpoint( code_commune=code_commune, frais=frais, profils=profils, - profils_precisions=profils_precisions, modes_accueil=modes_accueil, types=types, include_outdated=inclure_suspendus, @@ -378,6 +368,15 @@ def search_services_endpoint( """ ), ] = None, + profils_precisions: Annotated[ + Optional[str], + fastapi.Query( + description="""Une recherche elargie sur les profils. + Chaque résultat renvoyé correspond a la recherche fulltext sur + ce champs. + """ + ), + ] = None, types: Annotated[ Optional[list[di_schema.TypologieService]], fastapi.Query( @@ -444,6 +443,7 @@ def search_services_endpoint( frais=frais, modes_accueil=modes_accueil, profils=profils, + profils_precisions=profils_precisions, types=types, search_point=search_point, include_outdated=inclure_suspendus, diff --git a/api/src/data_inclusion/api/inclusion_data/services.py b/api/src/data_inclusion/api/inclusion_data/services.py index 19b85ee6..188e358c 100644 --- a/api/src/data_inclusion/api/inclusion_data/services.py +++ b/api/src/data_inclusion/api/inclusion_data/services.py @@ -137,6 +137,17 @@ def filter_services_by_profils( ) +def filter_services_by_profils_precisions( + query: sqla.Select, + profils_precisions: str, +): + return query.filter( + models.Service.searchable_index_profils_precisions.bool_op("@@")( + func.websearch_to_tsquery("french", profils_precisions) + ) + ) + + def filter_services_by_types( query: sqla.Select, types: list[di_schema.TypologieService], @@ -265,6 +276,7 @@ def filter_services( thematiques: list[di_schema.Thematique] | None = None, frais: list[di_schema.Frais] | None = None, profils: list[di_schema.Profil] | None = None, + profils_precisions: str | None = None, modes_accueil: list[di_schema.ModeAccueil] | None = None, types: list[di_schema.TypologieService] | None = None, include_outdated: bool | None = False, @@ -292,6 +304,9 @@ def filter_services( if not include_outdated: query = filter_outdated_services(query) + if profils_precisions is not None: + query = filter_services_by_profils_precisions(query, profils_precisions) + return query @@ -305,7 +320,6 @@ def list_services( code_commune: di_schema.CodeCommune | None = None, frais: list[di_schema.Frais] | None = None, profils: list[di_schema.Profil] | None = None, - profils_precisions: str | None = None, modes_accueil: list[di_schema.ModeAccueil] | None = None, types: list[di_schema.TypologieService] | None = None, include_outdated: bool | None = False, @@ -327,13 +341,6 @@ def list_services( if code_commune is not None: query = query.filter(models.Service.code_insee == code_commune) - if profils_precisions is not None: - query = query.filter( - models.Service.searchable_index_profils_precisions.bool_op("@@")( - func.websearch_to_tsquery("french", profils_precisions) - ) - ) - query = filter_services( query=query, sources=sources, @@ -362,6 +369,7 @@ def search_services( frais: list[di_schema.Frais] | None = None, modes_accueil: list[di_schema.ModeAccueil] | None = None, profils: list[di_schema.Profil] | None = None, + profils_precisions: str | None = None, types: list[di_schema.TypologieService] | None = None, search_point: str | None = None, include_outdated: bool | None = False, @@ -462,6 +470,7 @@ def search_services( thematiques=thematiques, frais=frais, profils=profils, + profils_precisions=profils_precisions, modes_accueil=modes_accueil, types=types, include_outdated=include_outdated,