42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"git.artlef.fr/bibliomane/internal/adapter"
|
|
"git.artlef.fr/bibliomane/internal/appcontext"
|
|
"git.artlef.fr/bibliomane/internal/dto"
|
|
"git.artlef.fr/bibliomane/internal/myvalidator"
|
|
"git.artlef.fr/bibliomane/internal/query"
|
|
)
|
|
|
|
func GetCollectionsHandler(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
|
|
}
|
|
collectionsDb, err := query.FetchAllCollections(ac.Db, user.ID, limit, offset)
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
collections := adapter.CollectionQueryToCollectionItemDto(collectionsDb)
|
|
count, err := query.FetchAllCollectionsCount(ac.Db, user.ID)
|
|
if err != nil {
|
|
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
|
return
|
|
}
|
|
ac.C.JSON(http.StatusOK, dto.CollectionItemsGet{Count: count, Collections: collections})
|
|
}
|