feat: 实现用户通知系统,包含通知模型、数据操作、业务逻辑及相关API接口。

This commit is contained in:
2026-01-28 08:08:14 +08:00
parent f1a390a1ef
commit 8e9c0e9024
5 changed files with 325 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
package models
import (
"time"
)
// NotificationType represents the type of notification
type NotificationType string
const (
NotificationTypeSystem NotificationType = "system"
NotificationTypeAlert NotificationType = "alert"
NotificationTypeInfo NotificationType = "info"
)
// Notification represents a system notification for a user
type Notification struct {
BaseModel
UserID uint `gorm:"not null;index" json:"user_id"`
Title string `gorm:"size:200;not null" json:"title"`
Content string `gorm:"type:text;not null" json:"content"`
Type NotificationType `gorm:"size:20;not null;default:'system'" json:"type"`
IsRead bool `gorm:"default:false" json:"is_read"`
Link string `gorm:"size:255" json:"link,omitempty"` // Optional link to redirect
ReadAt *time.Time `json:"read_at,omitempty"`
// Relationships
User User `gorm:"foreignKey:UserID" json:"-"`
}
// TableName specifies the table name for Notification
func (Notification) TableName() string {
return "notifications"
}