Skip to content

Commit

Permalink
✨ Add method to get a list of Ermittlungsauftraege with limit&offset (#3
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hf-kklein authored Feb 26, 2024
1 parent 0a711fa commit 10ee382
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 711 deletions.
3 changes: 3 additions & 0 deletions domain-specific-terms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ openend
adresse
objekt
oder
prozess
autor
titel
41 changes: 13 additions & 28 deletions src/bssclient/client/bssclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from aiohttp import BasicAuth, ClientSession, ClientTimeout

from bssclient.client.config import BssConfig
from bssclient.models.netzvertrag import Netzvertrag, _ListOfNetzvertraege
from bssclient.models.ermittlungsauftrag import Ermittlungsauftrag, _ListOfErmittlungsauftraege

_logger = logging.getLogger(__name__)


class BssClient:
"""
an async wrapper around the TMDS API
an async wrapper around the BSS API
"""

def __init__(self, config: BssConfig):
Expand Down Expand Up @@ -52,38 +52,23 @@ async def close_session(self):
await self._session.close()
self._session = None

async def get_netzvertraege_for_melo(self, melo_id: str) -> list[Netzvertrag]:
async def get_ermittlungsauftraege(self, limit: int = 0, offset: int = 0) -> list[Ermittlungsauftrag]:
"""
provide a melo id, e.g. 'DE1234567890123456789012345678901' and get the corresponding netzvertrag
get all ermittlungsauftrage in the specified range
"""
if not melo_id:
raise ValueError("You must not provide an empty melo_id")
session = await self._get_session()
request_url = self._config.server_url / "api" / "Netzvertrag" / "find" % {"messlokation": melo_id}
request_url = (
self._config.server_url
/ "api"
/ "Aufgabe"
/ "ermittlungsauftraege"
% {"limit": limit, "offset": offset, "includeDetails": "true"}
)
request_uuid = uuid.uuid4()
_logger.debug("[%s] requesting %s", str(request_uuid), request_url)
async with session.get(request_url) as response:
response.raise_for_status() # endpoint returns an empty list but no 404
_logger.debug("[%s] response status: %s", str(request_uuid), response.status)
response_json = await response.json()
_list_of_netzvertraege = _ListOfNetzvertraege.model_validate(response_json)
return _list_of_netzvertraege.root

async def get_netzvertrag_by_id(self, nv_id: uuid.UUID) -> Netzvertrag | None:
"""
provide a UUID, get the matching netzvertrag in return (or None, if 404)
"""
session = await self._get_session()
request_url = self._config.server_url / "api" / "Netzvertrag" / str(nv_id)
request_uuid = uuid.uuid4()
_logger.debug("[%s] requesting %s", str(request_uuid), request_url)
async with session.get(request_url) as response:
try:
if response.status == 404:
return None
response.raise_for_status()
finally:
_logger.debug("[%s] response status: %s", str(request_uuid), response.status)
response_json = await response.json()
result = Netzvertrag.model_validate(response_json)
return result
_list_of_ermittlungsauftraege = _ListOfErmittlungsauftraege.model_validate(response_json)
return _list_of_ermittlungsauftraege.root
57 changes: 57 additions & 0 deletions src/bssclient/models/ermittlungsauftrag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
models for Ermittlungsauftrag/Investigation Order
"""

from typing import Literal
from uuid import UUID

from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel

from bssclient.models.prozess import Prozess


class Notiz(BaseModel):
"""
Notiz am Ermittlungsauftrag
"""

autor: str
zeitpunkt: AwareDatetime | None = None
inhalt: str
timestamp: AwareDatetime
guid: UUID


class Ermittlungsauftrag(BaseModel):
"""
an investigation order
"""

model_config = ConfigDict(extra="allow", populate_by_name=True)
id: UUID
flat_id: str = Field(alias="flatId")
"""
the external ID of the respective Wohneinheit
"""
marktloaktion_id: str = Field(alias="marktlokationId")
"""
malo id
"""
messlokation_id: str = Field(alias="messlokationId")
"""
melo id
"""
zaehlernummer: str = Field(alias="zaehlernummer")
vertrag_id: UUID = Field(alias="vertragId")
"""
ID of the respective netzvertrag
"""
lieferbeginn: AwareDatetime
lieferende: AwareDatetime | None
notizen: list[Notiz]
kategorie: Literal["Ermittlungsauftrag"]
prozess: Prozess


class _ListOfErmittlungsauftraege(RootModel[list[Ermittlungsauftrag]]):
pass
53 changes: 0 additions & 53 deletions src/bssclient/models/netzvertrag.py

This file was deleted.

28 changes: 28 additions & 0 deletions src/bssclient/models/prozess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
models for BSS Prozess
"""

from uuid import UUID

from pydantic import BaseModel, Field


class Prozess(BaseModel):
"""
a bss prozess
"""

id: UUID
status: str
status_text: str = Field(alias="statusText")
typ: str
ausloeser: str
externe_id: str = Field(alias="externeId")
marktlokation: str
ide_referenz: str = Field(alias="ideReferenz")
transaktionsgrund: str
ausloeser_daten: str = Field(alias="ausloeserDaten")
antwort_status: str = Field(alias="antwortStatus")
einheit: str
messlokation: str
zaehlernummer: str
Loading

0 comments on commit 10ee382

Please sign in to comment.