Skip to content

Commit

Permalink
feat: ajout endpoint /api/v1/vessels/trackedCount
Browse files Browse the repository at this point in the history
  • Loading branch information
herve.le-bars committed Nov 22, 2024
1 parent cd17253 commit 3031be7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 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,12 @@ def __init__(
) -> Callable[..., AbstractContextManager]:
self.session_factory = session_factory


def get_vessel_tracked_count(self, session: Session) -> int:
stmt = select(func.count(sql_model.Vessel.id)).select_from(sql_model.Vessel)\
.distinct().where(sql_model.Vessel.tracking_activated == True)
return session.execute(stmt).scalar()

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()]
Expand Down
10 changes: 10 additions & 0 deletions backend/bloom/routers/v1/vessels.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
router = APIRouter()


@router.get("/vessels/trackedCount")
async def list_vessel_tracked(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_tracked_count(session)

@router.get("/vessels/types")
async def list_vessel_types(request: Request, # used by @cache
key: str = Depends(X_API_KEY_HEADER)):
Expand Down

0 comments on commit 3031be7

Please sign in to comment.