From 933c4f27e3b04af4e31373a1af7e27561fc64d2b Mon Sep 17 00:00:00 2001 From: Nicholas Wallace Date: Sun, 25 Feb 2024 01:10:41 +0000 Subject: [PATCH] Finishing initial `CollectionController` endpoints --- server/controllers/CollectionController.js | 121 ++++++++++++++++++++- 1 file changed, 118 insertions(+), 3 deletions(-) diff --git a/server/controllers/CollectionController.js b/server/controllers/CollectionController.js index f37574810..b035f2a13 100644 --- a/server/controllers/CollectionController.js +++ b/server/controllers/CollectionController.js @@ -285,13 +285,13 @@ class CollectionController { * application/json: * schema: * $ref: '#/components/schemas/collectionExpanded' + * 400: + * description: The provided library ID could not be found, is in + * a different library, or is already in a collection * 403: * description: A user with update permissions is required to update collections * 404: * description: No collection with the specified ID exists - * 500: - * description: The provided library ID could not be found, is in - * a different library, or is already in a collection */ async addBook(req, res) { const libraryItem = await Database.libraryItemModel.getOldById(req.body.id) @@ -326,6 +326,39 @@ class CollectionController { * @param {*} req * @param {*} res */ + /** + * @openapi + * /api/collections/{id}/book/{bookId}: + * delete: + * operationId: collectionRemoveBook + * summary: Remove a single book from a collection + * tags: + * - Collections + * parameters: + * - name: id + * in: path + * description: Collection ID + * required: true + * schema: + * type: string + * - name: bookId + * in: path + * description: Book ID + * required: true + * schema: + * type: string + * responses: + * 200: + * description: OK + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/collectionExpanded' + * 403: + * description: A user with update permissions is required to update collections + * 404: + * description: No collection with the specified ID exists + */ async removeBook(req, res) { const libraryItem = await Database.libraryItemModel.getOldById(req.params.bookId) if (!libraryItem) { @@ -370,6 +403,47 @@ class CollectionController { * @param {*} req * @param {*} res */ + /** + * @openapi + * /api/collections/{id}/batch/add: + * post: + * operationId: batchAddToCollection + * summary: Batch add books to an existing collection + * tags: + * - Collections + * parameters: + * - name: id + * in: path + * description: Collection ID + * required: true + * schema: + * type: string + * requestBody: + * description: Data for updating an existing collection + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * books: + * type: array + * items: + * type: string + * responses: + * 200: + * description: Collection created successfully + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/collectionExpanded' + * 403: + * description: A user with update permissions is required to update collections + * 404: + * description: No collection with the specified ID exists + * 500: + * description: The provided `books` array must not be empty + */ async addBatch(req, res) { // filter out invalid libraryItemIds const bookIdsToAdd = (req.body.books || []).filter(b => !!b && typeof b == 'string') @@ -428,6 +502,47 @@ class CollectionController { * @param {*} req * @param {*} res */ + /** + * @openapi + * /api/collections/{id}/batch/remove: + * post: + * operationId: batchRemoveFromCollection + * summary: Batch remove books from a collection + * tags: + * - Collections + * parameters: + * - name: id + * in: path + * description: Collection ID + * required: true + * schema: + * type: string + * requestBody: + * description: Data for updating an existing collection + * required: true + * content: + * application/json: + * schema: + * type: object + * properties: + * books: + * type: array + * items: + * type: string + * responses: + * 200: + * description: Books removed from collection successfully + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/collectionExpanded' + * 403: + * description: A user with update permissions is required to update collections + * 404: + * description: No collection with the specified ID exists + * 500: + * description: The provided `books` array must not be empty + */ async removeBatch(req, res) { // filter out invalid libraryItemIds const bookIdsToRemove = (req.body.books || []).filter(b => !!b && typeof b == 'string')