Move json struct in a new module

This commit is contained in:
2026-01-23 18:26:47 +01:00
parent e1fd12e233
commit 4ac0f4243d
10 changed files with 80 additions and 86 deletions

View File

@@ -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