Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ajout endpoint /api/v1/vessels/trackedCount #295

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading