1717class CollectionSchema (Schema ):
1818 uuid : str
1919 url : str
20+ api_url : str
2021 visibility : int = Field (ge = 0 , le = 2 )
2122 post_id : int | None = Field (alias = "latest_post_id" )
2223 created_time : datetime
@@ -50,7 +51,7 @@ class CollectionItemInSchema(Schema):
5051 tags = ["collection" ],
5152)
5253@paginate (PageNumberPagination )
53- def list_collections (request ):
54+ def list_user_collections (request ):
5455 """
5556 Get collections created by current user
5657 """
@@ -63,7 +64,7 @@ def list_collections(request):
6364 response = {200 : CollectionSchema , 401 : Result , 403 : Result , 404 : Result },
6465 tags = ["collection" ],
6566)
66- def get_collection (request , collection_uuid : str ):
67+ def get_user_collection (request , collection_uuid : str ):
6768 """
6869 Get collections by its uuid
6970 """
@@ -75,6 +76,48 @@ def get_collection(request, collection_uuid: str):
7576 return c
7677
7778
79+ @api .get (
80+ "/collection/{collection_uuid}" ,
81+ response = {200 : CollectionSchema , 401 : Result , 403 : Result , 404 : Result },
82+ tags = ["collection" ],
83+ auth = None ,
84+ )
85+ def get_collection (request , collection_uuid : str ):
86+ """
87+ Get details of a collection
88+ """
89+ c = Collection .get_by_url (collection_uuid )
90+ if not c :
91+ return 404 , {"message" : "Collection not found" }
92+ if not c .is_visible_to (request .user ):
93+ return 403 , {"message" : "Permission denied" }
94+ return c
95+
96+
97+ @api .get (
98+ "/collection/{collection_uuid}/item/" ,
99+ response = {200 : List [CollectionItemSchema ], 401 : Result , 403 : Result , 404 : Result },
100+ tags = ["collection" ],
101+ auth = None ,
102+ )
103+ @paginate (PageNumberPagination )
104+ def collection_list_items (request , collection_uuid : str ):
105+ """
106+ Get items in a collection collections
107+ """
108+ c = Collection .get_by_url (collection_uuid )
109+ if not c :
110+ return 404 , {"message" : "Collection not found" }
111+ if not c .is_visible_to (request .user ):
112+ return 403 , {"message" : "Permission denied" }
113+ if c .is_dynamic :
114+ items = c .query_result .items if c .query_result else []
115+ members = [{"item" : i , "note" : "" } for i in items ]
116+ return members
117+ else :
118+ return c .ordered_members
119+
120+
78121@api .post (
79122 "/me/collection/" ,
80123 response = {200 : CollectionSchema , 401 : Result , 403 : Result , 404 : Result },
@@ -140,7 +183,7 @@ def delete_collection(request, collection_uuid: str):
140183 tags = ["collection" ],
141184)
142185@paginate (PageNumberPagination )
143- def collection_list_items (request , collection_uuid : str ):
186+ def user_collection_list_items (request , collection_uuid : str ):
144187 """
145188 Get items in a collection collections
146189 """
0 commit comments