Files
ai-agent/internal/repositories/notification_repository.go
t 2bbf42b741 refactor(auth): delegate access control to be-system
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
2026-08-21 00:41:07 +08:00

69 lines
1.9 KiB
Go

package repositories
import (
"time"
"code.tczkiot.com/wlw/ai-agent/internal/models"
"code.tczkiot.com/wlw/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
}