init
This commit is contained in:
32
app/application/users/use_cases/get_user.py
Normal file
32
app/application/users/use_cases/get_user.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from uuid import UUID
|
||||
|
||||
from app.application.users.dto import UserDTO
|
||||
from app.application.users.ports.unit_of_work import UnitOfWork
|
||||
from app.domain.users.exceptions import UserNotFound
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class GetUserQuery:
|
||||
user_id: UUID
|
||||
|
||||
|
||||
class GetUserUseCase:
|
||||
def __init__(self, uow: UnitOfWork) -> None:
|
||||
self._uow = uow
|
||||
|
||||
async def execute(self, q: GetUserQuery) -> UserDTO:
|
||||
async with self._uow:
|
||||
user = await self._uow.users.get_by_id(q.user_id)
|
||||
if user is None:
|
||||
raise UserNotFound("User not found")
|
||||
|
||||
return UserDTO(
|
||||
id=user.id,
|
||||
email=str(user.email),
|
||||
full_name=user.full_name,
|
||||
is_active=user.is_active,
|
||||
created_at=user.created_at,
|
||||
)
|
||||
Reference in New Issue
Block a user