11import json
2+ from datetime import datetime
23from io import BytesIO
34from typing import Annotated
45
56from fastapi import Path as PathVar
6- from fastapi import Request , UploadFile , status
7+ from fastapi import Query , Request , UploadFile , status
78
89from decorators .auth import protected_route
910from endpoints .responses .collection import (
@@ -144,18 +145,26 @@ async def add_smart_collection(
144145
145146
146147@protected_route (router .get , "" , [Scope .COLLECTIONS_READ ])
147- def get_collections (request : Request ) -> list [CollectionSchema ]:
148+ def get_collections (
149+ request : Request ,
150+ updated_after : Annotated [
151+ datetime | None ,
152+ Query (
153+ description = "Filter collections updated after this datetime (ISO 8601 format with timezone information)."
154+ ),
155+ ] = None ,
156+ ) -> list [CollectionSchema ]:
148157 """Get collections endpoint
149158
150159 Args:
151160 request (Request): Fastapi Request object
152- id (int, optional): Collection id. Defaults to None.
161+ updated_after: Filter collections updated after this datetime
153162
154163 Returns:
155164 list[CollectionSchema]: List of collections
156165 """
157166
158- collections = db_collection_handler .get_collections ()
167+ collections = db_collection_handler .get_collections (updated_after = updated_after )
159168
160169 return CollectionSchema .for_user (request .user .id , [c for c in collections ])
161170
@@ -181,17 +190,28 @@ def get_virtual_collections(
181190
182191
183192@protected_route (router .get , "/smart" , [Scope .COLLECTIONS_READ ])
184- def get_smart_collections (request : Request ) -> list [SmartCollectionSchema ]:
193+ def get_smart_collections (
194+ request : Request ,
195+ updated_after : Annotated [
196+ datetime | None ,
197+ Query (
198+ description = "Filter smart collections updated after this datetime (ISO 8601 format with timezone information)."
199+ ),
200+ ] = None ,
201+ ) -> list [SmartCollectionSchema ]:
185202 """Get smart collections endpoint
186203
187204 Args:
188205 request (Request): Fastapi Request object
206+ updated_after: Filter smart collections updated after this datetime
189207
190208 Returns:
191209 list[SmartCollectionSchema]: List of smart collections
192210 """
193211
194- smart_collections = db_collection_handler .get_smart_collections (request .user .id )
212+ smart_collections = db_collection_handler .get_smart_collections (
213+ request .user .id , updated_after = updated_after
214+ )
195215
196216 return SmartCollectionSchema .for_user (
197217 request .user .id , [s for s in smart_collections ]
@@ -216,7 +236,7 @@ def get_collection(request: Request, id: int) -> CollectionSchema:
216236
217237 if collection .user_id != request .user .id and not collection .is_public :
218238 raise CollectionPermissionError (id )
219-
239+
220240 return CollectionSchema .model_validate (collection )
221241
222242
@@ -414,7 +434,7 @@ async def delete_collection(
414434 collection = db_collection_handler .get_collection (id )
415435 if not collection :
416436 raise CollectionNotFoundInDatabaseException (id )
417-
437+
418438 if collection .user_id != request .user .id :
419439 raise CollectionPermissionError (id )
420440
0 commit comments