Coverage for app/ddd/presentation/endpoint/token/create_token.py: 100%
11 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
2from fastapi.param_functions import Form
3from sqlmodel import Session
5from app.ddd.application.dto.token import CreateTokenInputDTO, CreateTokenOutputDTO
6from app.ddd.application.usecase.token import CreateTokenUseCase
7from app.ddd.infrastructure.database.db import get_session
8from app.ddd.infrastructure.uow import UserUnitOfWorkImpl
9from app.ddd.presentation.endpoint.token.router import router
10from app.ddd.presentation.schema.token import CreateTokenResponse
13def __usecase(session: Session = Depends(get_session)) -> CreateTokenUseCase:
14 return CreateTokenUseCase(uow=UserUnitOfWorkImpl(session))
16@router.post(
17 path="/token",
18 response_model=CreateTokenResponse,
19 # responses={
20 # status.HTTP_409_CONFLICT: UserDuplicationError(user_id="dammy").response(),
21 # },
22)
23def create_token(
24 user_id: str = Form(examples=["admin"], validation_alias="userId", alias="userId"),
25 user_password: str = Form(examples=["admin"], validation_alias="userPassword", alias="userPassword"),
26 usecase: CreateTokenUseCase = Depends(__usecase),
27) -> CreateTokenResponse:
28 """トークンを作成する."""
29 input_dto: CreateTokenInputDTO = CreateTokenInputDTO(
30 user_id = user_id,
31 user_password = user_password
32 )
33 output_dto: CreateTokenOutputDTO = usecase.execute(input_dto)
35 return CreateTokenResponse.model_validate(output_dto)