Manage display of book covers

This commit is contained in:
2025-10-28 18:35:36 +01:00
parent 8b8eee8210
commit b4df375e4c
20 changed files with 257 additions and 353 deletions

View File

@@ -7,8 +7,9 @@ import (
)
type bookPostCreate struct {
Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"`
Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"`
CoverID uint `json:"coverId"`
}
func PostBookHandler(ac appcontext.AppContext) {
@@ -18,6 +19,11 @@ func PostBookHandler(ac appcontext.AppContext) {
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
return
}
err = myvalidator.ValidateId(ac.Db, book.CoverID, &model.StaticFile{})
if err != nil {
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
return
}
user, fetchUserErr := ac.GetAuthenticatedUser()
if fetchUserErr != nil {
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
@@ -33,9 +39,13 @@ func PostBookHandler(ac appcontext.AppContext) {
}
func bookWsToDb(b bookPostCreate, user *model.User) model.Book {
return model.Book{
book := model.Book{
Title: b.Title,
Author: b.Author,
AddedBy: *user,
}
if b.CoverID > 0 {
book.CoverID = b.CoverID
}
return book
}