Coverage for app/ddd/presentation/endpoint/user/patch_user.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-15 01:44 +0000
« 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
4from app.ddd.application.dto.user import PatchUserInputDTO, PatchUserOutputDTO
5from app.ddd.application.usecase.user import PatchUserUseCase
6from app.ddd.domain import UserNotFoundError, UserUpdateConflictError
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 PatchUserResponse, PatchUsersRequest
13def __usecase(session: Session = Depends(get_session)) -> PatchUserUseCase:
14 return PatchUserUseCase(uow=UserUnitOfWorkImpl(session))
17@router.patch(
18 path="/users/{userId}",
19 response_model=PatchUserResponse,
20 responses={
21 status.HTTP_404_NOT_FOUND: UserNotFoundError(user_id="dammy").response(),
22 status.HTTP_409_CONFLICT: UserUpdateConflictError(user_id="dammy").response(),
23 },
24)
25def patch_user(
26 request: PatchUsersRequest,
27 user_id: str = Path(..., alias="userId"),
28 usecase: PatchUserUseCase = Depends(__usecase),
29) -> PatchUserResponse:
30 """
31 Userを更新する.
33 更新しない場合、入力しない。
34 """
35 input_dto: PatchUserInputDTO = PatchUserInputDTO.model_validate({"user_id": user_id, **request.model_dump(exclude_unset=True)})
36 dto: PatchUserOutputDTO = usecase.execute(input_dto)
37 return PatchUserResponse.model_validate(dto)