Add position for book in collection
This commit is contained in:
@@ -56,7 +56,7 @@ func PostCollectionBookHandler(ac appcontext.AppContext) {
|
||||
return
|
||||
}
|
||||
|
||||
collection.Books = append(collection.Books, book)
|
||||
ac.Db.Save(&collection)
|
||||
item := model.CollectionItem{Position: 0, BookID: book.ID, CollectionID: collection.ID}
|
||||
ac.Db.Save(&item)
|
||||
ac.C.String(http.StatusOK, "Success")
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"git.artlef.fr/bibliomane/internal/adapter"
|
||||
"git.artlef.fr/bibliomane/internal/appcontext"
|
||||
"git.artlef.fr/bibliomane/internal/dto"
|
||||
"git.artlef.fr/bibliomane/internal/i18nresource"
|
||||
@@ -50,12 +51,13 @@ func GetCollectionHandler(ac appcontext.AppContext) {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
books, err := query.FetchCollectionBooks(ac.Db, user.ID, uint(collectionId), limit, offset)
|
||||
itemsQueryResult, err := query.FetchCollectionItems(ac.Db, user.ID, uint(collectionId), limit, offset)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
return
|
||||
}
|
||||
collection.Books = books
|
||||
items := adapter.CollectionItemsQueryToDto(itemsQueryResult)
|
||||
collection.Items = items
|
||||
count, err := query.FetchCollectionBooksCount(ac.Db, user.ID, uint(collectionId))
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
|
||||
Reference in New Issue
Block a user