49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
|
"git.artlef.fr/PersonalLibraryManager/internal/myvalidator"
|
|
"git.artlef.fr/PersonalLibraryManager/internal/query"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func GetMyBooksWantReadHandler(ac appcontext.AppContext) {
|
|
user, err := ac.GetAuthenticatedUser()
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
limit, err := ac.GetQueryLimit()
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
offset, err := ac.GetQueryOffset()
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
userbooks, err := query.FetchWantReadUserBook(ac.Db, user.ID, limit, offset)
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
ac.C.JSON(http.StatusOK, userbooks)
|
|
}
|
|
|
|
func GetMyBooksWantReadCountHandler(ac appcontext.AppContext) {
|
|
user, err := ac.GetAuthenticatedUser()
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
count, err := query.FetchWantReadUserBookCount(ac.Db, user.ID)
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
ac.C.JSON(http.StatusOK, gin.H{"count": count})
|
|
}
|