Update GetEbookRating API to return rating 0 when no rating exists

This commit is contained in:
2026-01-26 11:49:44 -05:00
parent a1b070610a
commit f35defd139
+6 -2
View File
@@ -346,8 +346,12 @@ func (h *Handler) GetEbookRating(c echo.Context) error {
})
if err != nil {
if err == pgx.ErrNoRows {
// If no rating found, return 404
return c.JSON(http.StatusNotFound, map[string]string{"error": "rating not found"})
// If no rating found, return rating 0
return c.JSON(http.StatusOK, map[string]interface{}{
"ebook_id": ebookIdStr,
"user_id": userID,
"rating": 0,
})
}
return c.JSON(http.StatusInternalServerError, map[string]string{"error": err.Error()})
}