基础项目
Some checks failed
CI / init (pull_request) Has been cancelled
CI / Frontend node 18.16.0 (pull_request) Has been cancelled
CI / Backend go (1.22) (pull_request) Has been cancelled
CI / release-pr (pull_request) Has been cancelled
CI / devops-test (1.22, 18.16.0) (pull_request) Has been cancelled
CI / release-please (pull_request) Has been cancelled
CI / devops-prod (1.22, 18.x) (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
Some checks failed
CI / init (pull_request) Has been cancelled
CI / Frontend node 18.16.0 (pull_request) Has been cancelled
CI / Backend go (1.22) (pull_request) Has been cancelled
CI / release-pr (pull_request) Has been cancelled
CI / devops-test (1.22, 18.16.0) (pull_request) Has been cancelled
CI / release-please (pull_request) Has been cancelled
CI / devops-prod (1.22, 18.x) (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
This commit is contained in:
56
server/service/book/book_author.go
Normal file
56
server/service/book/book_author.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package book
|
||||
|
||||
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"
|
||||
commonReq "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
|
||||
)
|
||||
|
||||
type BookAuthorService struct{}
|
||||
|
||||
func (s *BookAuthorService) CreateBookAuthor(item book.BookAuthor) error {
|
||||
if err := validateBookAuthor(item); err != nil {
|
||||
return err
|
||||
}
|
||||
return global.GVA_DB.Create(&item).Error
|
||||
}
|
||||
|
||||
func (s *BookAuthorService) DeleteBookAuthor(item book.BookAuthor) error {
|
||||
return global.GVA_DB.Delete(&item).Error
|
||||
}
|
||||
|
||||
func (s *BookAuthorService) DeleteBookAuthorByIds(ids commonReq.IdsReq) error {
|
||||
return deleteByIDs[book.BookAuthor](ids.Ids)
|
||||
}
|
||||
|
||||
func (s *BookAuthorService) UpdateBookAuthor(item book.BookAuthor) error {
|
||||
if err := validateBookAuthor(item); err != nil {
|
||||
return err
|
||||
}
|
||||
return global.GVA_DB.Save(&item).Error
|
||||
}
|
||||
|
||||
func (s *BookAuthorService) GetBookAuthor(id uint) (item book.BookAuthor, err error) {
|
||||
err = global.GVA_DB.Where("id = ?", id).First(&item).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (s *BookAuthorService) GetBookAuthorInfoList(info bookReq.BookAuthorSearch) (list []book.BookAuthor, total int64, err error) {
|
||||
db := global.GVA_DB.Model(&book.BookAuthor{})
|
||||
if info.Name != "" {
|
||||
db = db.Where("name LIKE ?", "%"+info.Name+"%")
|
||||
}
|
||||
if info.Keyword != "" {
|
||||
db = db.Where("name LIKE ?", "%"+info.Keyword+"%")
|
||||
}
|
||||
if info.AuthorStatus != "" {
|
||||
db = db.Where("author_status = ?", info.AuthorStatus)
|
||||
}
|
||||
err = db.Count(&total).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = db.Scopes(paginate(info.PageInfo)).Order("id desc").Find(&list).Error
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user