Coverage for app/ddd/presentation/endpoint/group/get_group.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-15 01:44 +0000

1 

2from fastapi import Depends, Path, status 

3from sqlmodel import Session 

4 

5from app.ddd.application.dto.group import GetGroupInputDTO, GetGroupOutputDTO 

6from app.ddd.application.usecase.group import ( 

7 # GetGroupsUseCase, 

8 GetGroupUseCase, 

9) 

10from app.ddd.domain import GroupNotFoundError 

11from app.ddd.infrastructure.database.db import get_session 

12from app.ddd.infrastructure.uow import GroupUnitOfWorkImpl 

13from app.ddd.presentation.endpoint.group.router import router 

14from app.ddd.presentation.schema.group import GetGroupResponse 

15 

16 

17# ####################### 

18def __usecase(session: Session = Depends(get_session)) -> GetGroupUseCase: 

19 return GetGroupUseCase(uow=GroupUnitOfWorkImpl(session)) 

20 

21################ 

22@router.get( 

23 path="/groups/{groupId}", 

24 response_model=GetGroupResponse, 

25 responses={ 

26 status.HTTP_404_NOT_FOUND: GroupNotFoundError(group_id="dammy").response(), 

27 }, 

28) 

29def get_group( 

30 group_id: str = Path(..., alias="groupId"), 

31 usecase: GetGroupUseCase = Depends(__usecase), 

32) -> GetGroupResponse: 

33 """Groupを取得する.""" 

34 input_dto: GetGroupInputDTO = GetGroupInputDTO(group_id=group_id) 

35 dto: GetGroupOutputDTO = usecase.execute(input_dto) 

36 return GetGroupResponse.model_validate(dto) 

37 

38