Coverage for app/ddd/presentation/endpoint/group/create_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, status 

3from sqlmodel import Session 

4 

5from app.ddd.application.dto.group import CreateGroupInputDTO, CreateGroupOutputDTO 

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

7from app.ddd.domain import GroupDuplicationError 

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

9from app.ddd.infrastructure.uow import GroupUnitOfWorkImpl 

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

11from app.ddd.presentation.schema.group import CreateGroupRequest, CreateGroupResponse 

12 

13 

14def __usecase(session: Session = Depends(get_session)) -> CreateGroupUseCase: 

15 return CreateGroupUseCase(uow=GroupUnitOfWorkImpl(session)) 

16 

17 

18@router.post( 

19 path="/groups", 

20 # response_model=CreateGroupResponse, 

21 responses={ 

22 status.HTTP_409_CONFLICT: GroupDuplicationError(group_id="dammy").response(), 

23 }, 

24) 

25def create_group( 

26 request: CreateGroupRequest, 

27 # jwt_data: dict[str, Any] = Depends(jwt_data_depends), 

28 usecase: CreateGroupUseCase = Depends(__usecase), 

29) -> CreateGroupResponse: 

30 # return {} 

31 """Groupを作成する.""" 

32 input_dto: CreateGroupInputDTO = CreateGroupInputDTO.model_validate( 

33 { 

34 "group_responsible_user_id": "admin", #jwt_data['sub'], 

35 **request.model_dump(exclude_unset=True) 

36 } 

37 ) 

38 dto: CreateGroupOutputDTO = usecase.execute(input_dto) 

39 return CreateGroupResponse.model_validate(dto)