Coverage for app/ddd/presentation/endpoint/user/create_user.py: 100%

16 statements  

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

1from fastapi import Depends, status 

2from sqlmodel import Session 

3 

4from app.ddd.application.dto.user import CreateUserInputDTO, CreateUserOutputDTO 

5from app.ddd.application.usecase.user import CreateUserUseCase 

6from app.ddd.domain import UserDuplicationError 

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

8from app.ddd.infrastructure.uow import UserUnitOfWorkImpl 

9from app.ddd.presentation.endpoint.user.router import router 

10from app.ddd.presentation.schema.user import CreateUserRequest, CreateUserResponse 

11 

12 

13def __usecase(session: Session = Depends(get_session)) -> CreateUserUseCase: 

14 return CreateUserUseCase(uow=UserUnitOfWorkImpl(session)) 

15 

16 

17@router.post( 

18 path="/users", 

19 response_model=CreateUserResponse, 

20 responses={ 

21 status.HTTP_409_CONFLICT: UserDuplicationError(user_id="dammy").response(), 

22 }, 

23) 

24def create_user( 

25 request: CreateUserRequest, 

26 usecase: CreateUserUseCase = Depends(__usecase), 

27) -> CreateUserResponse: 

28 """Userを作成する.""" 

29 input_dto: CreateUserInputDTO = CreateUserInputDTO.model_validate(request) 

30 dto: CreateUserOutputDTO = usecase.execute(input_dto) 

31 return CreateUserResponse.model_validate(dto)