99from stac_fastapi .types .links import CollectionLinks , ItemLinks , resolve_links
1010
1111
12- @attr .s # type:ignore
12+ @attr .s
1313class Serializer (abc .ABC ):
14- """Defines serialization methods between the API and the data model."""
14+ """Defines serialization methods between the API and the data model.
15+
16+ This class is meant to be subclassed and implemented by specific serializers for different STAC objects (e.g. Item, Collection).
17+ """
1518
1619 @classmethod
1720 @abc .abstractmethod
1821 def db_to_stac (cls , item : dict , base_url : str ) -> Any :
19- """Transform database model to stac."""
22+ """Transform database model to STAC object.
23+
24+ Arguments:
25+ item (dict): A dictionary representing the database model.
26+ base_url (str): The base URL of the STAC API.
27+
28+ Returns:
29+ Any: A STAC object, e.g. an `Item` or `Collection`, representing the input `item`.
30+ """
31+ ...
32+
33+ @classmethod
34+ @abc .abstractmethod
35+ def stac_to_db (cls , stac_object : Any , base_url : str ) -> dict :
36+ """Transform STAC object to database model.
37+
38+ Arguments:
39+ stac_object (Any): A STAC object, e.g. an `Item` or `Collection`.
40+ base_url (str): The base URL of the STAC API.
41+
42+ Returns:
43+ dict: A dictionary representing the database model.
44+ """
2045 ...
2146
2247
@@ -25,14 +50,14 @@ class ItemSerializer(Serializer):
2550
2651 @classmethod
2752 def stac_to_db (cls , stac_data : stac_types .Item , base_url : str ) -> stac_types .Item :
28- """Transform STAC Item to database-ready STAC Item .
29-
30- :param stac_data: STAC Item object to be transformed.
31- :type stac_data: stac_types.Item
32- :param base_url: Base URL for the STAC API.
33- :type base_url: str
34- :return: A database-ready STAC Item object.
35- :rtype: stac_types.Item
53+ """Transform STAC item to database-ready STAC item .
54+
55+ Args:
56+ stac_data ( stac_types.Item): The STAC item object to be transformed.
57+ base_url (str): The base URL for the STAC API.
58+
59+ Returns:
60+ stac_types.Item: The database-ready STAC item object.
3661 """
3762 item_links = ItemLinks (
3863 collection_id = stac_data ["collection" ],
@@ -49,14 +74,14 @@ def stac_to_db(cls, stac_data: stac_types.Item, base_url: str) -> stac_types.Ite
4974
5075 @classmethod
5176 def db_to_stac (cls , item : dict , base_url : str ) -> stac_types .Item :
52- """Transform database model to STAC item.
53-
54- :param item: Database model to be transformed.
55- :type item: dict
56- :param base_url: Base URL for the STAC API.
57- :type base_url: str
58- :return: A STAC Item object.
59- :rtype: stac_types.Item
77+ """Transform database-ready STAC item to STAC item.
78+
79+ Args:
80+ item ( dict): The database-ready STAC item to be transformed.
81+ base_url (str): The base URL for the STAC API.
82+
83+ Returns:
84+ stac_types.Item: The STAC item object.
6085 """
6186 item_id = item ["id" ]
6287 collection_id = item ["collection" ]
@@ -88,15 +113,14 @@ class CollectionSerializer(Serializer):
88113 @classmethod
89114 def db_to_stac (cls , collection : dict , base_url : str ) -> stac_types .Collection :
90115 """Transform database model to STAC collection.
91-
116+
92117 Args:
93118 collection (dict): The collection data in dictionary form, extracted from the database.
94119 base_url (str): The base URL for the collection.
95-
120+
96121 Returns:
97122 stac_types.Collection: The STAC collection object.
98123 """
99-
100124 # Use dictionary unpacking to extract values from the collection dictionary
101125 collection_id = collection .get ("id" )
102126 stac_extensions = collection .get ("stac_extensions" , [])
0 commit comments