feat: add book admin display fields

This commit is contained in:
2026-04-27 13:53:37 +08:00
parent 67c33d06be
commit 2fa15625b0
20 changed files with 472 additions and 70 deletions

View File

@@ -4,11 +4,15 @@ import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/book"
bookReq "github.com/flipped-aurora/gin-vue-admin/server/model/book/request"
bookRes "github.com/flipped-aurora/gin-vue-admin/server/model/book/response"
commonReq "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"gorm.io/gorm"
)
type BookCommentService struct{}
const bookCommentDisplaySelect = "bc.*, b.title AS book_title, ch.title AS chapter_title"
func (s *BookCommentService) CreateBookComment(item book.BookComment) error {
if err := validateBookComment(item); err != nil {
return err
@@ -31,29 +35,38 @@ func (s *BookCommentService) UpdateBookComment(item book.BookComment) error {
return global.GVA_DB.Save(&item).Error
}
func (s *BookCommentService) GetBookComment(id uint) (item book.BookComment, err error) {
err = global.GVA_DB.Where("id = ?", id).First(&item).Error
func (s *BookCommentService) GetBookComment(id uint) (item bookRes.BookCommentDisplay, err error) {
err = bookCommentDisplayDB().
Select(bookCommentDisplaySelect).
Where("bc.id = ?", id).
Take(&item).Error
return
}
func (s *BookCommentService) GetBookCommentInfoList(info bookReq.BookCommentSearch) (list []book.BookComment, total int64, err error) {
db := global.GVA_DB.Model(&book.BookComment{})
func (s *BookCommentService) GetBookCommentInfoList(info bookReq.BookCommentSearch) (list []bookRes.BookCommentListItem, total int64, err error) {
db := bookCommentDisplayDB()
if info.MemberUserID != nil {
db = db.Where("member_user_id = ?", *info.MemberUserID)
db = db.Where("bc.member_user_id = ?", *info.MemberUserID)
}
if info.BookID != nil {
db = db.Where("book_id = ?", *info.BookID)
db = db.Where("bc.book_id = ?", *info.BookID)
}
if info.ChapterID != nil {
db = db.Where("chapter_id = ?", *info.ChapterID)
db = db.Where("bc.chapter_id = ?", *info.ChapterID)
}
if info.CommentStatus != "" {
db = db.Where("comment_status = ?", info.CommentStatus)
db = db.Where("bc.comment_status = ?", info.CommentStatus)
}
err = db.Count(&total).Error
if err != nil {
return
}
err = db.Scopes(paginate(info.PageInfo)).Order("id desc").Find(&list).Error
err = db.Select(bookCommentDisplaySelect).Scopes(paginate(info.PageInfo)).Order("bc.id desc").Scan(&list).Error
return
}
func bookCommentDisplayDB() *gorm.DB {
return global.GVA_DB.Table("book_comment AS bc").
Joins("LEFT JOIN book AS b ON b.id = bc.book_id").
Joins("LEFT JOIN book_chapter AS ch ON ch.id = bc.chapter_id")
}