70 lines
2.1 KiB
Go
Raw Normal View History

2025-06-06 18:30:12 +08:00
package repo
import (
"admin/apps/game/domain/entity"
"admin/apps/game/model"
"admin/internal/errcode"
"gorm.io/gorm"
)
var NoticeRepoInstance INoticeRepo
type INoticeRepo interface {
List(projectId int) ([]*entity.CommonResource, error)
2025-06-09 13:50:00 +08:00
DisableAll(projectId int) error
EnableAll(projectId int) error
DisableSome(projectId int, ids []int) error
EnableSome(projectId int, ids []int) error
2025-06-06 18:30:12 +08:00
}
func NewNoticeRepo(db *gorm.DB) INoticeRepo {
return &noticeRepoImpl{db: db}
}
type noticeRepoImpl struct {
db *gorm.DB
}
func (impl *noticeRepoImpl) List(projectId int) ([]*entity.CommonResource, error) {
list := make([]*model.Notice, 0)
2025-06-09 13:50:00 +08:00
err := impl.db.Where("project_id = ? and status = ?", projectId, true).Find(&list).Error
2025-06-06 18:30:12 +08:00
if err != nil {
return nil, errcode.New(errcode.DBError, "list server error:%v", err)
}
list1 := make([]*entity.CommonResource, 0, len(list))
for _, v := range list {
list1 = append(list1, (&entity.CommonResource{}).FromPo(v))
}
return list1, nil
}
2025-06-09 13:50:00 +08:00
func (impl *noticeRepoImpl) DisableAll(projectId int) error {
err := impl.db.Model(&model.Notice{}).Where("project_id = ?", projectId).Update("status", false).Error
if err != nil {
return errcode.New(errcode.DBError, "disable all error:%v", err)
}
return nil
}
func (impl *noticeRepoImpl) EnableAll(projectId int) error {
err := impl.db.Model(&model.Notice{}).Where("project_id = ?", projectId).Update("status", true).Error
if err != nil {
return errcode.New(errcode.DBError, "enable all error:%v", err)
}
return nil
}
func (impl *noticeRepoImpl) DisableSome(projectId int, ids []int) error {
err := impl.db.Model(&model.Notice{}).Where("project_id = ? and id in ?", projectId, ids).Update("status", false).Error
if err != nil {
return errcode.New(errcode.DBError, "disable all error:%v", err)
}
return nil
}
func (impl *noticeRepoImpl) EnableSome(projectId int, ids []int) error {
err := impl.db.Model(&model.Notice{}).Where("project_id = ? and id in ?", projectId, ids).Update("status", true).Error
if err != nil {
return errcode.New(errcode.DBError, "disable all error:%v", err)
}
return nil
}