72 lines
2.8 KiB
Go
72 lines
2.8 KiB
Go
package pet
|
|
|
|
import (
|
|
"context"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|
"github.com/flipped-aurora/gin-vue-admin/server/model/pet"
|
|
petReq "github.com/flipped-aurora/gin-vue-admin/server/model/pet/request"
|
|
)
|
|
|
|
type PetAdoptionPostsService struct{}
|
|
|
|
// CreatePetAdoptionPosts 创建petAdoptionPosts表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petAdoptionPostsService *PetAdoptionPostsService) CreatePetAdoptionPosts(ctx context.Context, petAdoptionPosts *pet.PetAdoptionPosts) (err error) {
|
|
err = global.GVA_DB.Create(petAdoptionPosts).Error
|
|
return err
|
|
}
|
|
|
|
// DeletePetAdoptionPosts 删除petAdoptionPosts表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petAdoptionPostsService *PetAdoptionPostsService) DeletePetAdoptionPosts(ctx context.Context, ID string) (err error) {
|
|
err = global.GVA_DB.Delete(&pet.PetAdoptionPosts{}, "id = ?", ID).Error
|
|
return err
|
|
}
|
|
|
|
// DeletePetAdoptionPostsByIds 批量删除petAdoptionPosts表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petAdoptionPostsService *PetAdoptionPostsService) DeletePetAdoptionPostsByIds(ctx context.Context, IDs []string) (err error) {
|
|
err = global.GVA_DB.Delete(&[]pet.PetAdoptionPosts{}, "id in ?", IDs).Error
|
|
return err
|
|
}
|
|
|
|
// UpdatePetAdoptionPosts 更新petAdoptionPosts表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petAdoptionPostsService *PetAdoptionPostsService) UpdatePetAdoptionPosts(ctx context.Context, petAdoptionPosts pet.PetAdoptionPosts) (err error) {
|
|
err = global.GVA_DB.Model(&pet.PetAdoptionPosts{}).Where("id = ?", petAdoptionPosts.ID).Updates(&petAdoptionPosts).Error
|
|
return err
|
|
}
|
|
|
|
// GetPetAdoptionPosts 根据ID获取petAdoptionPosts表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petAdoptionPostsService *PetAdoptionPostsService) GetPetAdoptionPosts(ctx context.Context, ID string) (petAdoptionPosts pet.PetAdoptionPosts, err error) {
|
|
err = global.GVA_DB.Where("id = ?", ID).First(&petAdoptionPosts).Error
|
|
return
|
|
}
|
|
|
|
// GetPetAdoptionPostsInfoList 分页获取petAdoptionPosts表记录
|
|
// Author [yourname](https://github.com/yourname)
|
|
func (petAdoptionPostsService *PetAdoptionPostsService) GetPetAdoptionPostsInfoList(ctx context.Context, info petReq.PetAdoptionPostsSearch) (list []pet.PetAdoptionPosts, total int64, err error) {
|
|
limit := info.PageSize
|
|
offset := info.PageSize * (info.Page - 1)
|
|
// 创建db
|
|
db := global.GVA_DB.Model(&pet.PetAdoptionPosts{})
|
|
var petAdoptionPostss []pet.PetAdoptionPosts
|
|
// 如果有条件搜索 下方会自动创建搜索语句
|
|
if len(info.CreatedAtRange) == 2 {
|
|
db = db.Where("created_at BETWEEN ? AND ?", info.CreatedAtRange[0], info.CreatedAtRange[1])
|
|
}
|
|
|
|
err = db.Count(&total).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if limit != 0 {
|
|
db = db.Limit(limit).Offset(offset)
|
|
}
|
|
|
|
err = db.Find(&petAdoptionPostss).Error
|
|
return petAdoptionPostss, total, err
|
|
}
|