Coverage for app/ddd/application/usecase/user/patch_user_usecase.py: 100%

11 statements  

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

1from app.ddd.application.dto.user import PatchUserInputDTO, PatchUserOutputDTO 

2from app.ddd.application.usecase.user.base_user_usecase import BaseUserUseCase 

3from app.ddd.domain import UserId 

4from app.ddd.infrastructure.auth.hash_password import create_hashed_password 

5 

6 

7class PatchUserUseCase(BaseUserUseCase[PatchUserInputDTO, PatchUserOutputDTO]): 

8 def execute(self, input_dto: PatchUserInputDTO) -> PatchUserOutputDTO: 

9 user_id = UserId(root=input_dto.user_id) 

10 user = self._uow.user_repository.find_by_id(user_id) 

11 user.sqlmodel_update(input_dto.model_dump(exclude_unset=True)) 

12 hashed_password=create_hashed_password(str(user.user_password)) 

13 # print(hashed_password) 

14 user.user_password = hashed_password 

15 with self._uow: 

16 self._uow.user_repository.update(user) 

17 return PatchUserOutputDTO.model_validate(user)