Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecuyer committed Oct 28, 2024
1 parent 4c7abef commit a4b2ced
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"""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
"""

import sqlalchemy as sa
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

Expand Down
20 changes: 10 additions & 10 deletions api/src/data_inclusion/api/inclusion_data/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
25 changes: 17 additions & 8 deletions api/src/data_inclusion/api/inclusion_data/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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


Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a4b2ced

Please sign in to comment.