diff --git a/internal/handlers/collections.go b/internal/handlers/collections.go index 215975b..8e9df74 100644 --- a/internal/handlers/collections.go +++ b/internal/handlers/collections.go @@ -306,6 +306,43 @@ func (h *CollectionHandler) RemoveBook(c echo.Context) error { return c.NoContent(http.StatusNoContent) } +type BulkRemoveBooksRequest struct { + BookIDs []string `json:"book_ids" validate:"required"` +} + +func (h *CollectionHandler) BulkRemoveBooks(c echo.Context) error { + collectionID, err := uuid.Parse(c.Param("id")) + if err != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid collection id"}) + } + + var req BulkRemoveBooksRequest + if err := c.Bind(&req); err != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid request"}) + } + if err := c.Validate(&req); err != nil { + return c.JSON(http.StatusBadRequest, map[string]string{"error": err.Error()}) + } + + removedCount := 0 + for _, bookIDStr := range req.BookIDs { + bookID, err := uuid.Parse(bookIDStr) + if err != nil { + continue + } + + err = h.collectionService.RemoveBookFromCollection(c.Request().Context(), collectionID, bookID) + if err == nil { + removedCount++ + } + } + + return c.JSON(http.StatusOK, map[string]interface{}{ + "removed": removedCount, + "total": len(req.BookIDs), + }) +} + func (h *CollectionHandler) GetDeviceMappings(c echo.Context) error { deviceID, err := uuid.Parse(c.Param("id")) if err != nil { diff --git a/internal/handlers/ebook.go b/internal/handlers/ebook.go index d07ddc2..eac20e3 100644 --- a/internal/handlers/ebook.go +++ b/internal/handlers/ebook.go @@ -81,6 +81,7 @@ func SetupRoutes(g *echo.Group, db *database.Queries, connManager *wsync.Connect collections.GET("/:id/books", collectionHandler.GetBookCollections) collections.POST("/:id/books", collectionHandler.AddBooks) collections.DELETE("/:id/books/:bookId", collectionHandler.RemoveBook) + collections.POST("/:id/books/bulk-remove", collectionHandler.BulkRemoveBooks) collections.POST("/test-rules", collectionHandler.TestRules) // Device shelf mapping routes diff --git a/templates/collections.templ b/templates/collections.templ index a7ec276..b464f61 100644 --- a/templates/collections.templ +++ b/templates/collections.templ @@ -240,10 +240,21 @@ templ CollectionDetail(user User, collection CollectionDetailData, books []BookD
-

Books in this Collection

- +
+

Books in this Collection

+ +
+
+ + +
@@ -252,22 +263,29 @@ templ CollectionDetail(user User, collection CollectionDetailData, books []BookD } for _, book := range books { -
-
- Cover +
+ +
+ Cover +
+
+

{ book.Title }

+ if book.Author != "" { +

by { book.Author }

+ } + +
-

{ book.Title }

- if book.Author != "" { -

by { book.Author }

- } -
}
@@ -299,6 +317,8 @@ templ CollectionDetail(user User, collection CollectionDetailData, books []BookD ") + templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "

Add Books to Collection

Search and select books to add to this collection.

") if templ_7745c5c3_Err != nil { return templ_7745c5c3_Err }