Created
December 3, 2022 08:32
-
-
Save akhundMurad/21f093ee88ed0654777a2485240d758c to your computer and use it in GitHub Desktop.
Read Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from src.application.ports.uow import IUnitOfWork | |
| from src.application.ports.analytics_gateway import IAnalyticsGateway | |
| from src.domain.analytics.queries.analytics_query import AnalyticsQuery, AnalyticsQueryResult | |
| class AnalyticsQueryHandler: | |
| def __init__(self, uow: IUnitOfWork, analytics_gateway: IAnalyticsGateway): | |
| self._uow = uow | |
| self._analytics_gateway = analytics_gateway | |
| def handle(self, query: AnalyticsQuery) -> AnalyticsQueryResult: | |
| with self._uow: | |
| result = self._analytics_gateway.find(id=query.campaign_id, start_date=query.start_date, end_date=query.end_date) | |
| return AnalyticsQueryResult(total_hours=result.hours, total_budget=result.budget, expenses=result.expenses) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import date | |
| from uuid import UUID | |
| from pydantic import Field | |
| from src.domain.base.query import Query, QueryResult | |
| class AnalyticsQuery(Query): | |
| campaign_id: UUID = Field(...) | |
| start_date: date = Field(...) | |
| end_date: date = Field(...) | |
| class AnalyticsQueryResult(QueryResult): | |
| total_hours: int = Field(0) | |
| total_budget: float = Field(0) | |
| expenses: float = Field(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment