feat: add user endpoints
This commit is contained in:
42
src/application/commands/user_commands.py
Normal file
42
src/application/commands/user_commands.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from src.application.abstractions import IUnitOfWork
|
||||
from src.application.contracts import ILogger
|
||||
from src.application.domain.entities.organization import PartySearchEntity
|
||||
from src.application.domain.entities.user import UserEntity
|
||||
from src.application.domain.enums.account_type import AccountType
|
||||
from src.infrastructure.database.decorators import transactional
|
||||
|
||||
|
||||
class ListUsersCommand:
|
||||
def __init__(self, unit_of_work: IUnitOfWork, logger: ILogger):
|
||||
self._unit_of_work = unit_of_work
|
||||
self._logger = logger
|
||||
|
||||
@transactional
|
||||
async def __call__(
|
||||
self,
|
||||
*,
|
||||
limit: int = 50,
|
||||
offset: int = 0,
|
||||
search: str | None = None,
|
||||
) -> tuple[list[UserEntity], int]:
|
||||
items = await self._unit_of_work.user_repository.list_all(
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
search=search,
|
||||
)
|
||||
total = await self._unit_of_work.user_repository.count_all(search=search)
|
||||
return items, total
|
||||
|
||||
|
||||
class GetUserCommand:
|
||||
def __init__(self, unit_of_work: IUnitOfWork, logger: ILogger):
|
||||
self._unit_of_work = unit_of_work
|
||||
self._logger = logger
|
||||
|
||||
@transactional
|
||||
async def __call__(self, user_id: str) -> UserEntity:
|
||||
return await self._unit_of_work.user_repository.get_by_id(user_id)
|
||||
Reference in New Issue
Block a user