Coverage for app/ddd/presentation/endpoint/user_report/create_user_report.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 (
5 CreateUserReportInputDTO,
6 CreateUserReportOutputDTO,
7)
8from app.ddd.application.usecase.user import CreateUserReportUseCase
9from app.ddd.domain import UserNotFoundError
10from app.ddd.infrastructure.database.db import get_session
11from app.ddd.infrastructure.uow import UserUnitOfWorkImpl
12from app.ddd.presentation.endpoint.user_report.router import router
13from app.ddd.presentation.schema.user_report import (
14 CreateUserReportRequest,
15 CreateUserReportResponse,
16)
19def __usecase(session: Session = Depends(get_session)) -> CreateUserReportUseCase:
20 return CreateUserReportUseCase(uow=UserUnitOfWorkImpl(session))
23@router.post(
24 path="/users/{userId}/user-reports",
25 response_model=CreateUserReportResponse,
26 responses={
27 status.HTTP_404_NOT_FOUND: UserNotFoundError(user_id="dammy").response(),
28 # status.HTTP_409_CONFLICT: UserDuplicationError(user_id="dammy").response(),
29 },
30)
31def create_user_report(
32 request: CreateUserReportRequest,
33 user_id: str = Path(..., alias="userId"),
34 usecase: CreateUserReportUseCase = Depends(__usecase),
35) -> CreateUserReportResponse:
36 """Userレポートを作成する."""
37 input_dto: CreateUserReportInputDTO = CreateUserReportInputDTO.model_validate({"user_id": user_id, **request.model_dump(exclude_unset=True)})
38 dto: CreateUserReportOutputDTO = usecase.execute(input_dto)
39 return CreateUserReportResponse.model_validate(dto)