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

16 statements  

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

1"""Module for defining endpoints for managing authors.""" 

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.authors.presenters import JsonApiAuthorsPresenter 

9from kwai.core.db.database import Database 

10from kwai.core.json_api import PaginationModel 

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

12from kwai.modules.portal.get_authors import GetAuthors, GetAuthorsCommand 

13from kwai.modules.portal.repositories.author_db_repository import AuthorDbRepository 

14 

15 

16router = APIRouter() 

17 

18 

19@router.get( 

20 "/authors", 

21 summary="Get all authors", 

22 responses={200: {"description": "Ok."}, 401: {"description": "Not Authorized."}}, 

23) 

24async def get( 

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

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

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

28): 

29 """Get all authors.""" 

30 command = GetAuthorsCommand( 

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

32 ) 

33 presenter = JsonApiAuthorsPresenter() 

34 await GetAuthors(AuthorDbRepository(database), presenter).execute(command) 

35 return presenter.get_document()