EUForest 96808d531a
Application device interface encryption and other bug fixes (#87)
* add: device login

* update: global config

* add: User transmission interface encryption

* update: get global config

* update: User transmission interface encryption

* add: get device list

* add: SecretIsEmpty Message

* update: device middleware

* add: query user subscribe node list

* fix bug: query device list

* fix bug: unbind device

* update: device login

* fix bug: The ad table is missing the description field

* fix bug:page size is zero

* update: Device Middleware

* fix bug: Site custom data update failed
2025-10-15 10:09:19 -04:00

50 lines
1.4 KiB
Go

package announcement
import (
"context"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
)
type customAnnouncementLogicModel interface {
GetAnnouncementListByPage(ctx context.Context, page, size int, filter Filter) (int64, []*Announcement, error)
}
// NewModel returns a model for the database table.
func NewModel(conn *gorm.DB, c *redis.Client) Model {
return &customAnnouncementModel{
defaultAnnouncementModel: newAnnouncementModel(conn, c),
}
}
type Filter struct {
Show *bool
Pinned *bool
Popup *bool
Search string
}
// GetAnnouncementListByPage get announcement list by page
func (m *customAnnouncementModel) GetAnnouncementListByPage(ctx context.Context, page, size int, filter Filter) (int64, []*Announcement, error) {
var list []*Announcement
var total int64
err := m.QueryNoCacheCtx(ctx, &list, func(conn *gorm.DB, v interface{}) error {
conn = conn.Model(&Announcement{})
if filter.Show != nil {
conn = conn.Where("`show` = ?", *filter.Show)
}
if filter.Pinned != nil {
conn = conn.Where("`pinned` = ?", *filter.Pinned)
}
if filter.Popup != nil {
conn = conn.Where("`popup` = ?", *filter.Popup)
}
if filter.Search != "" {
conn = conn.Where("`title` LIKE ? OR `content` LIKE ?", "%"+filter.Search+"%", "%"+filter.Search+"%")
}
return conn.Count(&total).Offset((page - 1) * size).Limit(size).Find(&list).Error
})
return total, list, err
}