feat: 实现用户通知系统,包含通知模型、数据操作、业务逻辑及相关API接口。
This commit is contained in:
34
internal/models/notification.go
Normal file
34
internal/models/notification.go
Normal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user