diff --git a/internal/handlers/collections.go b/internal/handlers/collections.go index 084bb14..2a1ec7e 100644 --- a/internal/handlers/collections.go +++ b/internal/handlers/collections.go @@ -356,11 +356,28 @@ func (h *CollectionHandler) RemoveBook(c echo.Context) error { return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid book id"}) } + // Get user from context for WebSocket broadcast + user := c.Get("user").(database.Users) + userUUID := uuid.UUID(user.ID.Bytes) + err = h.collectionService.RemoveBookFromCollection(c.Request().Context(), collectionID, bookID) if err != nil { return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()}) } + // Broadcast to user's other devices via WebSocket + if h.connManager != nil { + h.connManager.BroadcastToUser(userUUID.String(), wsync.BroadcastMessage{ + Type: "collection_updated", + Timestamp: time.Now().Format(time.RFC3339), + Data: map[string]interface{}{ + "collection_id": collectionID.String(), + "action": "book_removed", + "book_id": bookID.String(), + }, + }) + } + return c.NoContent(http.StatusNoContent) }