service_man/api/application/usecase/company/get_users_company.py

20 lines
923 B
Python
Raw Normal View History

from api.application.abstractions.transaction import TransactionContextManager
2024-04-23 12:08:56 +03:00
from api.application.contracts.company.company_request import CompanyByOwnerEmail
from api.application.contracts.company.company_response import CompanyBaseResponse
2024-04-08 23:55:30 +03:00
from api.domain.company.repository import CompanyRepository
class GetCompaniesByOwnerEmail:
def __init__(
self,
transaction: TransactionContextManager,
company_repository: CompanyRepository,
) -> None:
2024-04-08 23:55:30 +03:00
self.company_repository = company_repository
self.transaction = transaction
2024-04-08 23:55:30 +03:00
async def execute(self, request: CompanyByOwnerEmail) -> list[CompanyBaseResponse]:
async with self.transaction:
2024-04-23 12:08:56 +03:00
companies = await self.company_repository.get_companies_by_owner_email(filter={"email": request.email})
return [CompanyBaseResponse(name=comp.name.value, email=comp.email.value) for comp in companies]