Files
xuanzhi-service/server/model/book/request/book.go

129 lines
3.8 KiB
Go

package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/book"
commonReq "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
)
type BookSearch struct {
commonReq.PageInfo
Title string `json:"title" form:"title"`
BookType string `json:"bookType" form:"bookType"`
EraTag string `json:"eraTag" form:"eraTag"`
CompletionStatus string `json:"completionStatus" form:"completionStatus"`
PublishStatus string `json:"publishStatus" form:"publishStatus"`
SeriesID *uint `json:"seriesId" form:"seriesId"`
}
type BookAuthorSearch struct {
commonReq.PageInfo
Name string `json:"name" form:"name"`
IsEnabled *bool `json:"isEnabled" form:"isEnabled"`
}
type CreateBookAuthorReq struct {
Name string `json:"name" form:"name"`
IsEnabled *bool `json:"isEnabled" form:"isEnabled"`
Intro string `json:"intro" form:"intro"`
CoverUrl string `json:"coverUrl" form:"coverUrl"`
}
type BookAuthorRelationSearch struct {
commonReq.PageInfo
BookID *uint `json:"bookId" form:"bookId"`
AuthorID *uint `json:"authorId" form:"authorId"`
}
type BookChapterSearch struct {
commonReq.PageInfo
BookID *uint `json:"bookId" form:"bookId"`
IsReadable *bool `json:"isReadable" form:"isReadable"`
IsEnabled *bool `json:"isEnabled" form:"isEnabled"`
}
type CreateBookChapterReq struct {
BookID uint `json:"bookId" form:"bookId"`
Title string `json:"title" form:"title"`
ChapterNo int `json:"chapterNo" form:"chapterNo"`
IsReadable bool `json:"isReadable" form:"isReadable"`
ContentFileUrl string `json:"contentFileUrl" form:"contentFileUrl"`
TotalLines int `json:"totalLines" form:"totalLines"`
IsEnabled *bool `json:"isEnabled" form:"isEnabled"`
}
type BookCommentSearch struct {
commonReq.PageInfo
MemberUserID *uint `json:"memberUserId" form:"memberUserId"`
BookID *uint `json:"bookId" form:"bookId"`
ChapterID *uint `json:"chapterId" form:"chapterId"`
CommentStatus string `json:"commentStatus" form:"commentStatus"`
}
type BookCommentLikeRecordSearch struct {
commonReq.PageInfo
CommentID *uint `json:"commentId" form:"commentId"`
MemberUserID *uint `json:"memberUserId" form:"memberUserId"`
}
type BookFavoriteRecordSearch struct {
commonReq.PageInfo
MemberUserID *uint `json:"memberUserId" form:"memberUserId"`
BookID *uint `json:"bookId" form:"bookId"`
}
type BookReadRecordSearch struct {
commonReq.PageInfo
MemberUserID *uint `json:"memberUserId" form:"memberUserId"`
BookID *uint `json:"bookId" form:"bookId"`
}
type BookSeriesSearch struct {
commonReq.PageInfo
Name string `json:"name" form:"name"`
IsEnabled *bool `json:"isEnabled" form:"isEnabled"`
}
type CreateBookSeriesReq struct {
Name string `json:"name" form:"name"`
CoverUrl string `json:"coverUrl" form:"coverUrl"`
Intro string `json:"intro" form:"intro"`
IsEnabled *bool `json:"isEnabled" form:"isEnabled"`
}
func (req CreateBookAuthorReq) ToModel() book.BookAuthor {
return book.BookAuthor{
Name: req.Name,
IsEnabled: boolValueOrDefault(req.IsEnabled, true),
Intro: req.Intro,
CoverUrl: req.CoverUrl,
}
}
func (req CreateBookChapterReq) ToModel() book.BookChapter {
return book.BookChapter{
BookID: req.BookID,
Title: req.Title,
ChapterNo: req.ChapterNo,
IsReadable: req.IsReadable,
ContentFileUrl: req.ContentFileUrl,
TotalLines: req.TotalLines,
IsEnabled: boolValueOrDefault(req.IsEnabled, true),
}
}
func (req CreateBookSeriesReq) ToModel() book.BookSeries {
return book.BookSeries{
Name: req.Name,
CoverUrl: req.CoverUrl,
Intro: req.Intro,
IsEnabled: boolValueOrDefault(req.IsEnabled, true),
}
}
func boolValueOrDefault(value *bool, defaultValue bool) bool {
if value == nil {
return defaultValue
}
return *value
}