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:
@@ -246,7 +246,7 @@ func (h *Handler) CreateEbook(c echo.Context) error {
|
|||||||
ebook, err := h.db.CreateEbook(c.Request().Context(), database.CreateEbookParams{
|
ebook, err := h.db.CreateEbook(c.Request().Context(), database.CreateEbookParams{
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Author: pgtype.Text{String: req.Author, Valid: req.Author != ""},
|
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 != ""},
|
Description: pgtype.Text{String: req.Description, Valid: req.Description != ""},
|
||||||
FilePath: req.FilePath,
|
FilePath: req.FilePath,
|
||||||
FileSize: pgtype.Int8{Int64: req.FileSize, Valid: req.FileSize > 0},
|
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},
|
ID: pgtype.UUID{Bytes: id, Valid: true},
|
||||||
Title: req.Title,
|
Title: req.Title,
|
||||||
Author: pgtype.Text{String: req.Author, Valid: req.Author != ""},
|
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 != ""},
|
Description: pgtype.Text{String: req.Description, Valid: req.Description != ""},
|
||||||
CoverImagePath: pgtype.Text{String: req.CoverImagePath, Valid: req.CoverImagePath != ""},
|
CoverImagePath: pgtype.Text{String: req.CoverImagePath, Valid: req.CoverImagePath != ""},
|
||||||
Series: pgtype.Text{String: req.Series, Valid: req.Series != ""},
|
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.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{
|
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.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
|
// GetMediaItem handles GET /api/media-items/:id
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func (h *LibraryHandler) GetLibraryTypes(c echo.Context) error {
|
|||||||
|
|
||||||
// CreateLibrary creates a new library
|
// CreateLibrary creates a new library
|
||||||
func (h *LibraryHandler) CreateLibrary(c echo.Context) error {
|
func (h *LibraryHandler) CreateLibrary(c echo.Context) error {
|
||||||
user := c.Get("user").(*database.Users)
|
user := c.Get("user").(database.Users)
|
||||||
|
|
||||||
var req CreateLibraryRequest
|
var req CreateLibraryRequest
|
||||||
if err := c.Bind(&req); err != nil {
|
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.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
|
// GetUserVisibleLibraries retrieves libraries visible to the current user
|
||||||
func (h *LibraryHandler) GetUserVisibleLibraries(c echo.Context) error {
|
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)
|
libraries, err := h.libraryService.GetUserVisibleLibraries(c.Request().Context(), user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -234,7 +234,7 @@ func (h *LibraryHandler) DeleteLibraryFolder(c echo.Context) error {
|
|||||||
|
|
||||||
// SetLibraryVisibility sets library visibility for a user
|
// SetLibraryVisibility sets library visibility for a user
|
||||||
func (h *LibraryHandler) SetLibraryVisibility(c echo.Context) error {
|
func (h *LibraryHandler) SetLibraryVisibility(c echo.Context) error {
|
||||||
user := c.Get("user").(*database.Users)
|
user := c.Get("user").(database.Users)
|
||||||
|
|
||||||
var req SetLibraryVisibilityRequest
|
var req SetLibraryVisibilityRequest
|
||||||
if err := c.Bind(&req); err != nil {
|
if err := c.Bind(&req); err != nil {
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ func (s *EbookScanner) updateEbook(ctx context.Context, ebookID pgtype.UUID, fil
|
|||||||
ID: ebookID,
|
ID: ebookID,
|
||||||
Title: metadata.Title,
|
Title: metadata.Title,
|
||||||
Author: pgtype.Text{String: metadata.Author, Valid: metadata.Author != ""},
|
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 != ""},
|
Description: pgtype.Text{String: metadata.Description, Valid: metadata.Description != ""},
|
||||||
CoverImagePath: pgtype.Text{String: metadata.CoverPath, Valid: metadata.CoverPath != ""},
|
CoverImagePath: pgtype.Text{String: metadata.CoverPath, Valid: metadata.CoverPath != ""},
|
||||||
Series: pgtype.Text{String: metadata.Series, Valid: metadata.Series != ""},
|
Series: pgtype.Text{String: metadata.Series, Valid: metadata.Series != ""},
|
||||||
|
|||||||
Reference in New Issue
Block a user