@@ -178,6 +178,7 @@ public function deleteList(int $houseId, int $listId): DataResponse {
178178 *
179179 * @param int $houseId House id.
180180 * @param int $listId List id.
181+ * @param string $sortBy Sort mode (custom, newest, oldest, name_asc, name_desc).
181182 * @param int<1, 1000> $limit Maximum number of items to return.
182183 * @param int<0, max> $offset Number of items to skip.
183184 *
@@ -187,12 +188,12 @@ public function deleteList(int $houseId, int $listId): DataResponse {
187188 */
188189 #[ApiRoute(verb: 'GET ' , url: '/api/houses/{houseId}/lists/{listId}/items ' )]
189190 #[NoAdminRequired]
190- public function indexItems (int $ houseId , int $ listId , int $ limit = 200 , int $ offset = 0 ): DataResponse {
191- return $ this ->runAction (function () use ($ houseId , $ listId , $ limit , $ offset ): DataResponse {
191+ public function indexItems (int $ houseId , int $ listId , string $ sortBy = ' custom ' , int $ limit = 200 , int $ offset = 0 ): DataResponse {
192+ return $ this ->runAction (function () use ($ houseId , $ listId , $ sortBy , $ limit , $ offset ): DataResponse {
192193 $ this ->auth ->requireMember ($ houseId , $ this ->requireUid ());
193194 $ list = $ this ->lists ->getList ($ listId );
194195 $ this ->assertListInHouse ($ list ->getHouseId (), $ houseId );
195- $ all = $ this ->lists ->listItems ($ listId );
196+ $ all = $ this ->lists ->listItems ($ listId, $ sortBy );
196197 $ sliced = array_slice ($ all , max (0 , $ offset ), max (0 , $ limit ));
197198 $ items = array_map (fn ($ i ) => $ i ->jsonSerialize (), $ sliced );
198199 return new DataResponse ($ items );
@@ -385,6 +386,29 @@ public function deleteItem(int $houseId, int $listId, int $itemId): DataResponse
385386 });
386387 }
387388
389+ /**
390+ * Batch reorder items in a list
391+ *
392+ * @param int $houseId House id.
393+ * @param int $listId List id.
394+ * @param list<array{id: int, sortOrder: int}> $items Reorder entries.
395+ *
396+ * @return DataResponse<Http::STATUS_OK, PantrySuccess, array{}>
397+ *
398+ * 200: Items reordered
399+ */
400+ #[ApiRoute(verb: 'POST ' , url: '/api/houses/{houseId}/lists/{listId}/items/reorder ' )]
401+ #[NoAdminRequired]
402+ public function reorderItems (int $ houseId , int $ listId , array $ items = []): DataResponse {
403+ return $ this ->runAction (function () use ($ houseId , $ listId , $ items ): DataResponse {
404+ $ this ->auth ->requireMember ($ houseId , $ this ->requireUid ());
405+ $ list = $ this ->lists ->getList ($ listId );
406+ $ this ->assertListInHouse ($ list ->getHouseId (), $ houseId );
407+ $ this ->lists ->reorderItems ($ listId , $ items );
408+ return new DataResponse (['success ' => true ]);
409+ });
410+ }
411+
388412 /**
389413 * Upload an image for an item
390414 *
0 commit comments