JM-WechatMini/service/app/favorite.go
2023-11-02 04:34:46 +08:00

35 lines
869 B
Go

package app
import (
"miniapp/global"
"miniapp/model/app"
"miniapp/model/app/request"
)
type FavoriteService struct{}
// GetFavoriteList 获取收藏列表
func (f *FavoriteService) GetFavoriteList(p request.GetFavoriteList) (err error, list []app.Favorite, total int64) {
limit := p.PageSize
offset := p.PageSize * (p.Page - 1)
db := global.GVA_DB.Model(&app.Favorite{}).Where("user_id = ?", p.UserId)
err = db.Count(&total).Error
if err != nil {
return
}
err = db.Limit(limit).Offset(offset).Find(&list).Error
return
}
// CreateFavorite 创建收藏
func (f *FavoriteService) CreateFavorite(favorite *app.Favorite) (err error) {
err = global.GVA_DB.Create(&favorite).Error
return
}
// DeleteFavorite 删除收藏
func (f *FavoriteService) DeleteFavorite(favorite *app.Favorite) (err error) {
err = global.GVA_DB.Delete(&favorite).Error
return
}