Move json struct in a new module
This commit is contained in:
@@ -4,19 +4,14 @@ import (
|
||||
"errors"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/dto"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/model"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/myvalidator"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type bookPostCreate struct {
|
||||
Title string `json:"title" binding:"required,max=300"`
|
||||
Author string `json:"author" binding:"max=100"`
|
||||
CoverID uint `json:"coverId"`
|
||||
}
|
||||
|
||||
func PostBookHandler(ac appcontext.AppContext) {
|
||||
var book bookPostCreate
|
||||
var book dto.BookPostCreate
|
||||
err := ac.C.ShouldBindJSON(&book)
|
||||
if err != nil {
|
||||
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
|
||||
@@ -41,7 +36,7 @@ func PostBookHandler(ac appcontext.AppContext) {
|
||||
ac.C.String(200, "Success")
|
||||
}
|
||||
|
||||
func saveBookToDb(ac appcontext.AppContext, b bookPostCreate, user *model.User) error {
|
||||
func saveBookToDb(ac appcontext.AppContext, b dto.BookPostCreate, user *model.User) error {
|
||||
author, err := fetchOrCreateAuthor(ac, b.Author)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user