Files
ai-agent/internal/repositories/notification_repository.go
T
mlogclub 5d7c10aeab refactor: rename agent widget references to AI agent for consistency
- Updated runtime configuration to use __CS_AI_AGENT_WIDGET_CONFIG__ instead of __CS_AGENT_WIDGET_CONFIG__.
- Changed message types in support host bridge from "cs-agent" to "cs-ai-agent".
- Minified SDK script updated to reflect new AI agent naming conventions.
- Adjusted scrollbar styles in main.scss to use .cs-ai-agent-scrollbar instead of .cs-agent-scrollbar.
2026-05-30 21:19:36 +08:00

68 lines
1.8 KiB
Go

package repositories
import (
"time"
"cs-ai-agent/internal/models"
"cs-ai-agent/internal/pkg/httpx/params"
"github.com/mlogclub/simple/sqls"
"gorm.io/gorm"
)
var NotificationRepository = newNotificationRepository()
func newNotificationRepository() *notificationRepository {
return &notificationRepository{}
}
type notificationRepository struct {
}
func (r *notificationRepository) Get(db *gorm.DB, id int64) *models.Notification {
ret := &models.Notification{}
if err := db.First(ret, "id = ?", id).Error; err != nil {
return nil
}
return ret
}
func (r *notificationRepository) Find(db *gorm.DB, cnd *sqls.Cnd) (list []models.Notification) {
cnd.Find(db, &list)
return
}
func (r *notificationRepository) FindPageByParams(db *gorm.DB, params *params.QueryParams) (list []models.Notification, paging *sqls.Paging) {
return r.FindPageByCnd(db, &params.Cnd)
}
func (r *notificationRepository) FindPageByCnd(db *gorm.DB, cnd *sqls.Cnd) (list []models.Notification, paging *sqls.Paging) {
cnd.Find(db, &list)
count := cnd.Count(db, &models.Notification{})
paging = &sqls.Paging{
Page: cnd.Paging.Page,
Limit: cnd.Paging.Limit,
Total: count,
}
return
}
func (r *notificationRepository) Count(db *gorm.DB, cnd *sqls.Cnd) int64 {
return cnd.Count(db, &models.Notification{})
}
func (r *notificationRepository) Create(db *gorm.DB, item *models.Notification) error {
return db.Create(item).Error
}
func (r *notificationRepository) Updates(db *gorm.DB, id int64, columns map[string]any) error {
return db.Model(&models.Notification{}).Where("id = ?", id).Updates(columns).Error
}
func (r *notificationRepository) MarkAllRead(db *gorm.DB, userID int64, readAt time.Time) error {
return db.Model(&models.Notification{}).
Where("recipient_user_id = ? AND read_at IS NULL", userID).
Updates(map[string]any{"read_at": readAt}).Error
}