persistence for recurring api calls
All checks were successful
Build and push docker image / Build (pull_request) Successful in 1m48s
All checks were successful
Build and push docker image / Build (pull_request) Successful in 1m48s
This commit is contained in:
28
backend/src/structs/trip.py
Normal file
28
backend/src/structs/trip.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from .landmark import Landmark
|
||||
from .linked_landmarks import LinkedLandmarks
|
||||
import uuid
|
||||
|
||||
class Trip(BaseModel):
|
||||
uuid: str = Field(default_factory=uuid.uuid4)
|
||||
total_time: int
|
||||
first_landmark_uuid: str
|
||||
|
||||
|
||||
@classmethod
|
||||
def from_linked_landmarks(self, landmarks: LinkedLandmarks, cache_client) -> "Trip":
|
||||
"""
|
||||
Initialize a new Trip object and ensure it is stored in the cache.
|
||||
"""
|
||||
trip = Trip(
|
||||
total_time = landmarks.total_time,
|
||||
first_landmark_uuid = str(landmarks[0].uuid)
|
||||
)
|
||||
|
||||
# Store the trip in the cache
|
||||
cache_client.set(f"trip_{trip.uuid}", trip)
|
||||
for landmark in landmarks:
|
||||
cache_client.set(f"landmark_{landmark.uuid}", landmark)
|
||||
|
||||
return trip
|
||||
Reference in New Issue
Block a user