Coverage for src/kwai/api/v1/trainings/endpoints/coaches.py: 94%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-01-01 00:00 +0000

1"""Module for defining endpoints for coaches.""" 

2 

3from typing import Annotated 

4 

5from fastapi import APIRouter, Depends 

6 

7from kwai.api.dependencies import create_database 

8from kwai.api.v1.trainings.schemas.coach import CoachDocument 

9from kwai.core.db.database import Database 

10from kwai.core.json_api import Meta 

11from kwai.modules.training.coaches.coach_db_repository import CoachDbRepository 

12from kwai.modules.training.get_coaches import GetCoaches, GetCoachesCommand 

13 

14 

15router = APIRouter() 

16 

17 

18@router.get("/trainings/coaches") 

19async def get_coaches( 

20 database: Annotated[Database, Depends(create_database)], 

21) -> CoachDocument: 

22 """Get coaches.""" 

23 count, coach_iterator = await GetCoaches(CoachDbRepository(database)).execute( 

24 GetCoachesCommand(active=True) 

25 ) 

26 

27 document = CoachDocument(meta=Meta(count=count), data=[]) 

28 async for coach in coach_iterator: 

29 document.merge(CoachDocument.create(coach)) 

30 

31 return document