Update GetEbookRating API to return rating 0 when no rating exists
This commit is contained in:
@@ -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()})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user