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

@@ -1,28 +1,14 @@
package query
import (
"git.artlef.fr/PersonalLibraryManager/internal/dto"
"git.artlef.fr/PersonalLibraryManager/internal/fileutils"
"git.artlef.fr/PersonalLibraryManager/internal/model"
"gorm.io/gorm"
)
type BookGet struct {
Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"`
ISBN string `json:"isbn"`
InventaireId string `json:"inventaireid"`
OpenLibraryId string `json:"openlibraryid"`
Summary string `json:"summary"`
Rating int `json:"rating"`
Read bool `json:"read"`
WantRead bool `json:"wantread"`
StartReadDate string `json:"startReadDate"`
EndReadDate string `json:"endReadDate"`
CoverPath string `json:"coverPath"`
}
func FetchBookGet(db *gorm.DB, userId uint, bookId uint64) (BookGet, error) {
var book BookGet
func FetchBookGet(db *gorm.DB, userId uint, bookId uint64) (dto.BookGet, error) {
var book dto.BookGet
query := db.Model(&model.Book{})
selectQueryString := "books.title, authors.name as author, books.isbn, books.inventaire_id, books.open_library_id, books.summary, " +
"user_books.rating, user_books.read, user_books.want_read, " +
@@ -38,18 +24,8 @@ func FetchBookGet(db *gorm.DB, userId uint, bookId uint64) (BookGet, error) {
return book, res.Error
}
type BookUserGet struct {
ID uint `json:"id"`
Title string `json:"title" binding:"required,max=300"`
Author string `json:"author" binding:"max=100"`
Rating int `json:"rating" binding:"min=0,max=10"`
Read bool `json:"read" binding:"boolean"`
WantRead bool `json:"wantread" binding:"boolean"`
CoverPath string `json:"coverPath"`
}
func FetchReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]BookUserGet, error) {
var books []BookUserGet
func FetchReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGet, error) {
var books []dto.BookUserGet
query := fetchReadUserBookQuery(db, userId)
query = query.Limit(limit)
query = query.Offset(offset)
@@ -64,8 +40,8 @@ func FetchReadUserBookCount(db *gorm.DB, userId uint) (int64, error) {
return count, res.Error
}
func FetchReadingUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]BookUserGet, error) {
var books []BookUserGet
func FetchReadingUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGet, error) {
var books []dto.BookUserGet
query := fetchReadingUserBookQuery(db, userId)
query = query.Limit(limit)
query = query.Offset(offset)
@@ -91,8 +67,8 @@ func fetchReadingUserBookQuery(db *gorm.DB, userId uint) *gorm.DB {
return query
}
func FetchWantReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]BookUserGet, error) {
var books []BookUserGet
func FetchWantReadUserBook(db *gorm.DB, userId uint, limit int, offset int) ([]dto.BookUserGet, error) {
var books []dto.BookUserGet
query := fetchWantReadUserBookQuery(db, userId)
query = query.Limit(limit)