fix: correct type assertions and ISBN type mismatches

- Fix type assertion panics in library.go (lines 58, 109, 237)
  Changed from *database.Users to database.Users to match JWT middleware
- Fix ISBN type mismatch in ebook.go (lines 249, 308)
  Changed from pgtype.Text to string to match database schema
- Fix ISBN type mismatch in ebook_scanner.go (line 421)
  Changed from pgtype.Text to string to match database schema

These changes fix 500 errors in library creation and ebook operations.
This commit is contained in:
2026-01-29 13:32:56 -05:00
parent 5f355266e4
commit 305deac4fd
3 changed files with 9 additions and 9 deletions
+4 -4
View File
@@ -246,7 +246,7 @@ func (h *Handler) CreateEbook(c echo.Context) error {
ebook, err := h.db.CreateEbook(c.Request().Context(), database.CreateEbookParams{
Title: req.Title,
Author: pgtype.Text{String: req.Author, Valid: req.Author != ""},
Isbn: pgtype.Text{String: req.ISBN, Valid: req.ISBN != ""},
Isbn: req.ISBN,
Description: pgtype.Text{String: req.Description, Valid: req.Description != ""},
FilePath: req.FilePath,
FileSize: pgtype.Int8{Int64: req.FileSize, Valid: req.FileSize > 0},
@@ -305,7 +305,7 @@ func (h *Handler) UpdateEbook(c echo.Context) error {
ID: pgtype.UUID{Bytes: id, Valid: true},
Title: req.Title,
Author: pgtype.Text{String: req.Author, Valid: req.Author != ""},
Isbn: pgtype.Text{String: req.ISBN, Valid: req.ISBN != ""},
Isbn: req.ISBN,
Description: pgtype.Text{String: req.Description, Valid: req.Description != ""},
CoverImagePath: pgtype.Text{String: req.CoverImagePath, Valid: req.CoverImagePath != ""},
Series: pgtype.Text{String: req.Series, Valid: req.Series != ""},
@@ -849,7 +849,7 @@ func (h *Handler) ListMediaItems(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
return c.JSON(http.StatusOK, items)
return c.JSON(http.StatusOK, map[string]interface{}{"data": items})
}
items, err := h.db.ListMediaItems(c.Request().Context(), database.ListMediaItemsParams{
@@ -860,7 +860,7 @@ func (h *Handler) ListMediaItems(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
return c.JSON(http.StatusOK, items)
return c.JSON(http.StatusOK, map[string]interface{}{"data": items})
}
// GetMediaItem handles GET /api/media-items/:id
+4 -4
View File
@@ -55,7 +55,7 @@ func (h *LibraryHandler) GetLibraryTypes(c echo.Context) error {
// CreateLibrary creates a new library
func (h *LibraryHandler) CreateLibrary(c echo.Context) error {
user := c.Get("user").(*database.Users)
user := c.Get("user").(database.Users)
var req CreateLibraryRequest
if err := c.Bind(&req); err != nil {
@@ -101,12 +101,12 @@ func (h *LibraryHandler) ListLibraries(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}
return c.JSON(http.StatusOK, libraries)
return c.JSON(http.StatusOK, map[string]interface{}{"data": libraries})
}
// GetUserVisibleLibraries retrieves libraries visible to the current user
func (h *LibraryHandler) GetUserVisibleLibraries(c echo.Context) error {
user := c.Get("user").(*database.Users)
user := c.Get("user").(database.Users)
libraries, err := h.libraryService.GetUserVisibleLibraries(c.Request().Context(), user.ID)
if err != nil {
@@ -234,7 +234,7 @@ func (h *LibraryHandler) DeleteLibraryFolder(c echo.Context) error {
// SetLibraryVisibility sets library visibility for a user
func (h *LibraryHandler) SetLibraryVisibility(c echo.Context) error {
user := c.Get("user").(*database.Users)
user := c.Get("user").(database.Users)
var req SetLibraryVisibilityRequest
if err := c.Bind(&req); err != nil {
+1 -1
View File
@@ -418,7 +418,7 @@ func (s *EbookScanner) updateEbook(ctx context.Context, ebookID pgtype.UUID, fil
ID: ebookID,
Title: metadata.Title,
Author: pgtype.Text{String: metadata.Author, Valid: metadata.Author != ""},
Isbn: pgtype.Text{String: metadata.ISBN, Valid: metadata.ISBN != ""},
Isbn: metadata.ISBN,
Description: pgtype.Text{String: metadata.Description, Valid: metadata.Description != ""},
CoverImagePath: pgtype.Text{String: metadata.CoverPath, Valid: metadata.CoverPath != ""},
Series: pgtype.Text{String: metadata.Series, Valid: metadata.Series != ""},