-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: now we can see if formation
is_favirite
or not.
- Loading branch information
1 parent
f463dae
commit 7679505
Showing
11 changed files
with
149 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from src.business_logic.formation.scrap.utils.format_formations import ( | ||
format_formation_with_is_favorite, | ||
format_formations, | ||
) | ||
from src.business_logic.formation.scrap.types import FormationsWithTotal | ||
from src.business_logic.formation.scrap.utils.get_onisep_data import get_onisep_data | ||
|
||
|
||
def _get_raw_main_formations(limit: int = 10, offset: int = None) -> dict: | ||
params = f"/search?&size={limit}" | ||
if offset: | ||
params += f"&from={offset}" | ||
return get_onisep_data(params) | ||
|
||
|
||
def get_main_formations(limit: int = 10, offset: int = None) -> FormationsWithTotal: | ||
data = _get_raw_main_formations(limit, offset) | ||
|
||
formated_formations = format_formations(data["results"]) | ||
|
||
return FormationsWithTotal(data["total"], formated_formations) | ||
|
||
|
||
def auth_get_main_formations( | ||
user_id: int, limit: int = 10, offset: int = None | ||
) -> FormationsWithTotal: | ||
data = _get_raw_main_formations(limit, offset) | ||
|
||
formated_formations = format_formation_with_is_favorite(user_id, data["results"]) | ||
|
||
return FormationsWithTotal(data["total"], formated_formations) |
8 changes: 8 additions & 0 deletions
8
src/business_logic/formation/scrap/get_repartition_formations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from src.business_logic.formation.scrap.types import Facet | ||
from src.business_logic.formation.scrap.utils.get_onisep_data import get_onisep_data | ||
|
||
|
||
def get_libelle_type_formation(query: str) -> list[Facet]: | ||
params = f"/search?q={query}" | ||
data = get_onisep_data(params) | ||
return data["facets"]["libelle_type_formation"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from src.business_logic.formation.scrap.utils.format_formations import ( | ||
format_formation_with_is_favorite, | ||
format_formations, | ||
) | ||
from src.business_logic.formation.scrap.types import FormationsWithTotal | ||
from src.business_logic.formation.scrap.utils.get_onisep_data import get_onisep_data | ||
|
||
|
||
def _get_raw_search_data(query: str, limit: int, offset: int = None) -> dict: | ||
params = f"/search?q={query}&size={limit}" | ||
if offset: | ||
params += f"&from={offset}" | ||
return get_onisep_data(params) | ||
|
||
|
||
def search_formations( | ||
query: str, limit: int, offset: int = None | ||
) -> FormationsWithTotal: | ||
data = _get_raw_search_data(query, limit, offset) | ||
|
||
formated_formations = format_formations(data["results"]) | ||
|
||
return FormationsWithTotal(data["total"], formated_formations) | ||
|
||
|
||
def auth_search_formations( | ||
user_id: int, query: str, limit: int, offset: int = None | ||
) -> FormationsWithTotal: | ||
data = _get_raw_search_data(query, limit, offset) | ||
formated_formations = format_formation_with_is_favorite(user_id, data["results"]) | ||
|
||
return FormationsWithTotal(data["total"], formated_formations) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/business_logic/formation/scrap/utils/format_formations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from src.business_logic.favoris.is_favorite import check_if_is_favorite | ||
from src.business_logic.formation.scrap.types import ( | ||
FormationIsFavortite, | ||
) | ||
from src.models.formation import Formation | ||
|
||
|
||
def _create_formation_from_dict(formation: dict) -> Formation: | ||
return Formation( | ||
code_nsf=int(formation.get("code_nsf") or 0), | ||
type=formation.get("sigle_type_formation") | ||
or formation.get("libelle_type_formation"), | ||
libelle=formation.get("libelle_formation_principal"), | ||
tutelle=formation.get("tutelle"), | ||
url=formation.get("url_et_id_onisep"), | ||
domain=formation.get("domainesous-domaine"), | ||
niveau_de_sortie=formation.get("niveau_de_sortie_indicatif"), | ||
duree=formation.get("duree"), | ||
) | ||
|
||
|
||
def format_formations(data: list[dict]) -> list[Formation]: | ||
return [_create_formation_from_dict(formation).to_dict() for formation in data] | ||
|
||
|
||
def format_formation_with_is_favorite( | ||
user_id: int, data: list[dict] | ||
) -> list[FormationIsFavortite]: | ||
return [ | ||
FormationIsFavortite( | ||
formation=_create_formation_from_dict(formation).to_dict(), | ||
is_favorite=check_if_is_favorite(user_id, formation["url_et_id_onisep"]), | ||
) | ||
for formation in data | ||
] |
15 changes: 15 additions & 0 deletions
15
src/business_logic/formation/scrap/utils/get_onisep_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Idéo-Formations initiales en France | ||
# https://opendata.onisep.fr/data/5fa591127f501/2-ideo-formations-initiales-en-france.htm | ||
import requests | ||
from src.business_logic.formation import HEADERS, ONISEP_URL | ||
|
||
|
||
DATASET = "5fa591127f501" | ||
|
||
|
||
def get_onisep_data(params: str) -> dict: | ||
url = ONISEP_URL + DATASET + params | ||
response = requests.get(url, headers=HEADERS) | ||
if response.status_code == 200: | ||
return response.json() | ||
raise Exception("Onisep API is down.", response.status_code) |
File renamed without changes.