feat: add API to get daily consumption
This commit is contained in:
parent
9c883a8eca
commit
a0acb2950c
18 changed files with 278 additions and 6 deletions
31
server/app/services/consumption_service.py
Normal file
31
server/app/services/consumption_service.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from datetime import datetime
|
||||
|
||||
from domain.entities.consumption_point import ConsumptionResponse
|
||||
from domain.exceptions import ValidationError
|
||||
from domain.value_objects import Granularity
|
||||
from ports import ReadingQueryRepository
|
||||
|
||||
|
||||
class ConsumptionService:
|
||||
def __init__(self, repo: ReadingQueryRepository) -> None:
|
||||
self._repo = repo
|
||||
|
||||
def get_consumption(
|
||||
self,
|
||||
dev_eui: str,
|
||||
start: datetime,
|
||||
end: datetime,
|
||||
granularity: Granularity,
|
||||
) -> ConsumptionResponse:
|
||||
if start >= end:
|
||||
raise ValidationError("'start' doit être antérieur à 'end'")
|
||||
|
||||
points = self._repo.get_consumption(dev_eui, start, end, granularity)
|
||||
|
||||
return ConsumptionResponse(
|
||||
dev_eui=dev_eui,
|
||||
start=start,
|
||||
end=end,
|
||||
granularity=granularity,
|
||||
points=points,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue