init
This commit is contained in:
31
src/application/commands/organization_document_commands.py
Normal file
31
src/application/commands/organization_document_commands.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from src.application.abstractions import IUnitOfWork
|
||||
from src.application.contracts import ILogger
|
||||
from src.application.domain.entities.organization import OrganizationDocumentEntity
|
||||
from src.application.domain.exceptions import ApplicationException
|
||||
from src.infrastructure.database.decorators import transactional
|
||||
|
||||
|
||||
class ListOrganizationDocumentsCommand:
|
||||
def __init__(self, unit_of_work: IUnitOfWork, logger: ILogger):
|
||||
self._unit_of_work = unit_of_work
|
||||
self._logger = logger
|
||||
|
||||
@transactional
|
||||
async def __call__(self, organization_id: str) -> list[OrganizationDocumentEntity]:
|
||||
await self._unit_of_work.legal_entity_repository.get_by_id(organization_id)
|
||||
return await self._unit_of_work.organization_document_repository.list_by_organization(organization_id)
|
||||
|
||||
|
||||
class GetOrganizationDocumentCommand:
|
||||
def __init__(self, unit_of_work: IUnitOfWork, logger: ILogger):
|
||||
self._unit_of_work = unit_of_work
|
||||
self._logger = logger
|
||||
|
||||
@transactional
|
||||
async def __call__(self, organization_id: str, document_id: str) -> OrganizationDocumentEntity:
|
||||
doc = await self._unit_of_work.organization_document_repository.get_by_id(document_id)
|
||||
if doc.organization_id != organization_id:
|
||||
raise ApplicationException(status_code=404, message='Document not found')
|
||||
return doc
|
||||
Reference in New Issue
Block a user