-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgbfs_feed_impl.py
More file actions
35 lines (30 loc) · 1.44 KB
/
Copy pathgbfs_feed_impl.py
File metadata and controls
35 lines (30 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from shared.db_models.bounding_box_impl import BoundingBoxImpl
from shared.db_models.feed_impl import FeedImpl
from shared.db_models.gbfs_version_impl import GbfsVersionImpl
from shared.database_gen.sqlacodegen_models import Gbfsfeed as GbfsFeedOrm
from shared.db_models.location_impl import LocationImpl
from feeds_gen.models.gbfs_feed import GbfsFeed
class GbfsFeedImpl(FeedImpl, GbfsFeed):
"""Implementation of the `GtfsFeed` model.
This class converts a SQLAlchemy row DB object to a Pydantic model.
"""
class Config:
"""Pydantic configuration.
Enabling `from_attributes` method to create a model instance from a SQLAlchemy row object."""
from_attributes = True
@classmethod
def from_orm(cls, feed: GbfsFeedOrm | None) -> GbfsFeed | None:
gbfs_feed: GbfsFeed = super().from_orm(feed)
if not gbfs_feed:
return None
gbfs_feed.locations = [LocationImpl.from_orm(item) for item in feed.locations] if feed.locations else []
gbfs_feed.system_id = feed.system_id
gbfs_feed.provider_url = feed.operator_url
gbfs_feed.versions = (
[GbfsVersionImpl.from_orm(item) for item in feed.gbfsversions if item is not None]
if feed.gbfsversions
else []
)
gbfs_feed.bounding_box = BoundingBoxImpl.from_orm(feed.bounding_box)
gbfs_feed.bounding_box_generated_at = feed.bounding_box_generated_at
return gbfs_feed