增加流水通知审计分页

This commit is contained in:
yml
2026-05-24 17:51:00 +08:00
parent 03e5d211dc
commit cb636e4e89
21 changed files with 295 additions and 120 deletions
@@ -25,16 +25,21 @@ func NewRepository(db *gorm.DB) *Repository {
return &Repository{db: db}
}
func (r *Repository) List(userID uint64) ([]NotificationDTO, error) {
func (r *Repository) List(userID uint64, page, pageSize int) (*PaginatedResult, error) {
var total int64
if err := r.db.Model(&model.Notification{}).Where("user_id = ?", userID).Count(&total).Error; err != nil {
return nil, err
}
offset := (page - 1) * pageSize
var rows []model.Notification
if err := r.db.Where("user_id = ?", userID).Order("id DESC").Limit(100).Find(&rows).Error; err != nil {
if err := r.db.Where("user_id = ?", userID).Order("id DESC").Offset(offset).Limit(pageSize).Find(&rows).Error; err != nil {
return nil, err
}
items := make([]NotificationDTO, 0, len(rows))
for _, row := range rows {
items = append(items, toDTO(row))
}
return items, nil
return &PaginatedResult{Items: items, Total: total, Page: page, PageSize: pageSize}, nil
}
func (r *Repository) MarkRead(userID uint64, id uint64) error {