Coverage for app/ddd/presentation/endpoint/user/delete_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, Path, status 

2from sqlmodel import Session 

3 

4from app.ddd.application.dto.user import DeleteUserInputDTO, DeleteUserOutputDTO 

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

6from app.ddd.domain import UserNotFoundError 

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 DeleteUserResponse 

11 

12 

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

14 return DeleteUserUseCase(uow=UserUnitOfWorkImpl(session)) 

15 

16@router.delete( 

17 path="/users/{userId}", 

18 response_model=DeleteUserResponse, 

19 responses={ 

20 # TODO(nonomura): Error 1:n ErrorResponse.errors 

21 # status.HTTP_404_NOT_FOUND: UserNotFoundError(user_id='dammy').response(), 

22 status.HTTP_404_NOT_FOUND: { 

23 "content": { 

24 "application/json": { 

25 "example": { 

26 "detail": [ 

27 UserNotFoundError(user_id="dammy").camel_detail(), 

28 ] 

29 } 

30 } 

31 }, 

32 } 

33 }, 

34 

35) 

36def delete_user( 

37 user_id: str = Path(..., alias="userId"), 

38 usecase: DeleteUserUseCase = Depends(__usecase), 

39) -> DeleteUserResponse: 

40 """Userを削除する.""" 

41 input_dto: DeleteUserInputDTO = DeleteUserInputDTO(user_id=user_id) 

42 dto: DeleteUserOutputDTO = usecase.execute(input_dto) 

43 return DeleteUserResponse.model_validate(dto)