Finishing initial CollectionController endpoints

This commit is contained in:
Nicholas Wallace 2024-02-25 01:10:41 +00:00
parent 6321c76d32
commit 933c4f27e3

View file

@ -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')