User book API: use a single query with result and count
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"net/http"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/dto"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/myvalidator"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func GetMyBooksReadingHandler(ac appcontext.AppContext) {
|
||||
@@ -30,19 +30,10 @@ func GetMyBooksReadingHandler(ac appcontext.AppContext) {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
ac.C.JSON(http.StatusOK, userbooks)
|
||||
}
|
||||
|
||||
func GetMyBooksReadingCountHandler(ac appcontext.AppContext) {
|
||||
user, err := ac.GetAuthenticatedUser()
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
count, err := query.FetchReadingUserBookCount(ac.Db, user.ID)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
ac.C.JSON(http.StatusOK, gin.H{"count": count})
|
||||
ac.C.JSON(http.StatusOK, dto.BookUserGet{Count: count, Books: userbooks})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user