Skip to content

Commit 5381453

Browse files
authored
feat: add license information to operations API (#1506)
1 parent e7d703f commit 5381453

File tree

16 files changed

+655
-60
lines changed

16 files changed

+655
-60
lines changed

api/src/shared/db_models/feed_impl.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import logging
2+
3+
from sqlalchemy.orm import Session
4+
5+
from shared.database.database import with_db_session
16
from shared.db_models.basic_feed_impl import BaseFeedImpl
27
from feeds_gen.models.feed import Feed
3-
from shared.database_gen.sqlacodegen_models import Feed as FeedOrm
8+
from shared.database_gen.sqlacodegen_models import Feed as FeedOrm, License
49
from shared.db_models.external_id_impl import ExternalIdImpl
510
from shared.db_models.feed_related_link_impl import FeedRelatedLinkImpl
611

@@ -33,10 +38,18 @@ def from_orm(cls, feed_orm: FeedOrm | None) -> Feed | None:
3338
return feed
3439

3540
@classmethod
36-
def to_orm_from_dict(cls, feed_dict: dict | None) -> FeedOrm | None:
41+
@with_db_session
42+
def to_orm_from_dict(cls, feed_dict: dict | None, db_session: Session | None = None) -> FeedOrm | None:
3743
"""Convert a dictionary representation of a feed to a SQLAlchemy Feed ORM object."""
3844
if not feed_dict:
3945
return None
46+
license_id = None
47+
if feed_dict.get("license_id") is not None:
48+
license_orm = db_session.query(License).get(feed_dict["license_id"])
49+
if not license_orm:
50+
logging.warning("License with id %s not found.", feed_dict["license_id"])
51+
license_id = license_orm.id if license_orm else None
52+
4053
result: Feed = FeedOrm(
4154
id=feed_dict.get("id"),
4255
stable_id=feed_dict.get("stable_id"),
@@ -51,6 +64,8 @@ def to_orm_from_dict(cls, feed_dict: dict | None) -> FeedOrm | None:
5164
authentication_info_url=feed_dict.get("authentication_info_url"),
5265
api_key_parameter_name=feed_dict.get("api_key_parameter_name"),
5366
license_url=feed_dict.get("license_url"),
67+
license_id=license_id,
68+
license_notes=feed_dict.get("license_notes"),
5469
status=feed_dict.get("status"),
5570
official=feed_dict.get("official"),
5671
official_updated_at=feed_dict.get("official_updated_at"),

0 commit comments

Comments
 (0)