Coverage for src/kwai/api/v1/auth/endpoints/users.py: 75%

16 statements  

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

1"""Module that implement all users endpoints.""" 

2 

3from typing import Annotated 

4 

5from fastapi import APIRouter, Depends 

6 

7from kwai.api.dependencies import create_database, get_current_user 

8from kwai.api.v1.auth.presenters import JsonApiUserAccountPresenter 

9from kwai.core.db.database import Database 

10from kwai.core.json_api import PaginationModel 

11from kwai.modules.identity.get_user_accounts import ( 

12 GetUserAccounts, 

13 GetUserAccountsCommand, 

14) 

15from kwai.modules.identity.users.user import UserEntity 

16from kwai.modules.identity.users.user_account_db_repository import ( 

17 UserAccountDbRepository, 

18) 

19 

20 

21router = APIRouter() 

22 

23 

24@router.get( 

25 "", 

26 summary="Get all users", 

27 responses={ 

28 200: {"description": "Ok."}, 

29 401: {"description": "Not Authorized."}, 

30 }, 

31) 

32async def get( 

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

34 pagination: Annotated[PaginationModel, Depends(PaginationModel)], 

35 user: Annotated[UserEntity, Depends(get_current_user)], 

36): 

37 """Get all user accounts.""" 

38 command = GetUserAccountsCommand( 

39 offset=pagination.offset or 0, limit=pagination.limit or 0 

40 ) 

41 presenter = JsonApiUserAccountPresenter() 

42 await GetUserAccounts(UserAccountDbRepository(database), presenter).execute(command) 

43 return presenter.get_document()