@@ -99,77 +99,23 @@ def get_collection(self, collection_id: str, **kwargs) -> Collection:
99
99
return self .collection_serializer .db_to_stac (collection , base_url )
100
100
101
101
def item_collection (
102
- self , collection_id : str , limit : int = 10 , token : str = None , ** kwargs
102
+ self ,
103
+ collection_id : str ,
104
+ bbox : Optional [List [NumType ]] = None ,
105
+ datetime : Optional [Union [str , datetime ]] = None ,
106
+ limit : int = 10 ,
107
+ token : str = None ,
108
+ ** kwargs ,
103
109
) -> ItemCollection :
104
110
"""Read an item collection from the database."""
105
- base_url = str (kwargs ["request" ].base_url )
106
- with self .session .reader .context_session () as session :
107
- collection_children = (
108
- session .query (self .item_table )
109
- .join (self .collection_table )
110
- .filter (self .collection_table .id == collection_id )
111
- .order_by (self .item_table .datetime .desc (), self .item_table .id )
112
- )
113
- count = None
114
- if self .extension_is_enabled ("ContextExtension" ):
115
- count_query = collection_children .statement .with_only_columns (
116
- [func .count ()]
117
- ).order_by (None )
118
- count = collection_children .session .execute (count_query ).scalar ()
119
- token = self .get_token (token ) if token else token
120
- page = get_page (collection_children , per_page = limit , page = (token or False ))
121
- # Create dynamic attributes for each page
122
- page .next = (
123
- self .insert_token (keyset = page .paging .bookmark_next )
124
- if page .paging .has_next
125
- else None
126
- )
127
- page .previous = (
128
- self .insert_token (keyset = page .paging .bookmark_previous )
129
- if page .paging .has_previous
130
- else None
131
- )
132
-
133
- links = []
134
- if page .next :
135
- links .append (
136
- {
137
- "rel" : Relations .next .value ,
138
- "type" : "application/geo+json" ,
139
- "href" : f"{ kwargs ['request' ].base_url } collections/{ collection_id } /items?token={ page .next } &limit={ limit } " ,
140
- "method" : "GET" ,
141
- }
142
- )
143
- if page .previous :
144
- links .append (
145
- {
146
- "rel" : Relations .previous .value ,
147
- "type" : "application/geo+json" ,
148
- "href" : f"{ kwargs ['request' ].base_url } collections/{ collection_id } /items?token={ page .previous } &limit={ limit } " ,
149
- "method" : "GET" ,
150
- }
151
- )
152
-
153
- response_features = []
154
- for item in page :
155
- response_features .append (
156
- self .item_serializer .db_to_stac (item , base_url = base_url )
157
- )
158
-
159
- context_obj = None
160
- if self .extension_is_enabled ("ContextExtension" ):
161
- context_obj = {
162
- "returned" : len (page ),
163
- "limit" : limit ,
164
- "matched" : count ,
165
- }
166
-
167
- return ItemCollection (
168
- type = "FeatureCollection" ,
169
- features = response_features ,
170
- links = links ,
171
- context = context_obj ,
172
- )
111
+ return self .get_search (
112
+ collections = [collection_id ],
113
+ bbox = bbox ,
114
+ datetime = datetime ,
115
+ limit = limit ,
116
+ token = token ,
117
+ ** kwargs ,
118
+ )
173
119
174
120
def get_item (self , item_id : str , collection_id : str , ** kwargs ) -> Item :
175
121
"""Get item by id."""
0 commit comments