Skip to content

Commit

Permalink
Merge pull request #293 from dataforgoodfr/feat_274_api_listes_valeurs
Browse files Browse the repository at this point in the history
feat: 274 api listes valeurs types, classes, countries
  • Loading branch information
rv2931 authored Nov 22, 2024
2 parents 5538255 + 6b8ccf5 commit 7c423ee
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
12 changes: 12 additions & 0 deletions backend/bloom/infra/repositories/repository_vessel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ def __init__(
) -> Callable[..., AbstractContextManager]:
self.session_factory = session_factory

def get_vessel_types(self, session: Session) -> list[str]:
stmt = select(sql_model.Vessel.type).select_from(sql_model.Vessel).distinct()
return [i for i in session.execute(stmt).scalars()]

def get_vessel_length_classes(self, session: Session) -> list[str]:
stmt = select(sql_model.Vessel.length_class).select_from(sql_model.Vessel).distinct()
return [i for i in session.execute(stmt).scalars()]

def get_vessel_countries(self, session: Session) -> list[str]:
stmt = select(sql_model.Vessel.country_iso3).select_from(sql_model.Vessel).distinct()
return [i for i in session.execute(stmt).scalars()]

def get_vessel_by_id(self, session: Session, vessel_id: int) -> Union[Vessel, None]:
return session.get(sql_model.Vessel, vessel_id)

Expand Down
32 changes: 32 additions & 0 deletions backend/bloom/routers/v1/vessels.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@
router = APIRouter()


@router.get("/vessels/types")
async def list_vessel_types(request: Request, # used by @cache
key: str = Depends(X_API_KEY_HEADER)):
check_apikey(key)
use_cases = UseCases()
vessel_repository = use_cases.vessel_repository()
db = use_cases.db()
with db.session() as session:
return vessel_repository.get_vessel_types(session)


@router.get("/vessels/classes")
async def list_vessel_classes(request: Request, # used by @cache
key: str = Depends(X_API_KEY_HEADER)):
check_apikey(key)
use_cases = UseCases()
vessel_repository = use_cases.vessel_repository()
db = use_cases.db()
with db.session() as session:
return vessel_repository.get_vessel_length_classes(session)

@router.get("/vessels/countries")
async def list_vessel_countries(request: Request, # used by @cache
key: str = Depends(X_API_KEY_HEADER)):
check_apikey(key)
use_cases = UseCases()
vessel_repository = use_cases.vessel_repository()
db = use_cases.db()
with db.session() as session:
return vessel_repository.get_vessel_countries(session)


@router.get("/vessels")
@cache
async def list_vessels(request: Request, # used by @cache
Expand Down
5 changes: 2 additions & 3 deletions backend/bloom/routers/v1/zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,15 @@ async def list_zones_summary(request: Request,
return result


@router.get("/zones/all/categories")
@router.get("/zones/categories")
@cache
async def list_zone_categories(request: Request, nocache: bool = False, key: str = Depends(X_API_KEY_HEADER)):
check_apikey(key)
use_cases = UseCases()
zone_repository = use_cases.zone_repository()
db = use_cases.db()
with db.session() as session:
json_data = [ZoneListView(**z.model_dump_json())
for z in zone_repository.get_all_zone_categories(session)]
json_data = [z for z in zone_repository.get_all_zone_categories(session)]
return json_data


Expand Down

0 comments on commit 7c423ee

Please sign in to comment.