Manage display of book covers
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user