Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial code to test action #104

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions meldingen_core/actions/melding.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,27 @@ async def __call__(self, pk: int, values: dict[str, Any], token: str) -> T:
return melding


class MeldingAddLocationAction(Generic[T, T_co]):
_verify_token: TokenVerifier[T, T_co]
_repository: BaseMeldingRepository[T, T_co]

def __init__(
self,
repository: BaseMeldingRepository[T, T_co],
token_verifier: TokenVerifier[T, T_co],
) -> None:
self._repository = repository
self._verify_token = token_verifier

async def __call__(self, melding_id: int, token: str, location: dict[str, Any]) -> T:
melding = await self._verify_token(melding_id, token)

melding.geo_location = location
await self._repository.save(melding)

return melding


class BaseStateTransitionAction(Generic[T, T_co], metaclass=ABCMeta):
_state_machine: BaseMeldingStateMachine[T]
_repository: BaseMeldingRepository[T, T_co]
Expand Down
10 changes: 10 additions & 0 deletions meldingen_core/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import TypeVar
from abc import ABCMeta, abstractmethod
from meldingen_core.models import Melding

T = TypeVar("T", bound=Melding)

class MeldingLocationIngestor(metaclass=ABCMeta):

@abstractmethod
async def __call__(self, melding: Melding, geojson: dict) -> Melding: ...
2 changes: 2 additions & 0 deletions meldingen_core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from typing import Union
from dataclasses import dataclass, field
from datetime import datetime

Expand All @@ -18,6 +19,7 @@ class Melding:
token: str | None = None
token_expires: datetime | None = None
attachments: list["Attachment"] = field(default_factory=list)
geo_location: Union[str, bytes] | None = None # WKT or WKB


@dataclass
Expand Down
Loading