eventNotification

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeComment = "comment" // 评论通知
	EventTypeReply   = "reply"   // 回复通知
	EventTypeSystem  = "system"  // 系统通知
	EventTypeFollow  = "follow"  // 关注通知
)

Event Types

Variables

This section is empty.

Functions

func Create

func Create(entity *Entity) error

Create 创建通知

func DeleteNotification

func DeleteNotification(notificationId uint64, userId uint64) error

DeleteNotification 删除通知

func GetUnreadCount

func GetUnreadCount(userId uint64) (count int64, err error)

GetUnreadCount 获取用户未读通知数量

func MarkAllAsRead

func MarkAllAsRead(userId uint64) error

MarkAllAsRead 标记用户所有通知为已读

func MarkAsRead

func MarkAsRead(notificationId uint64, userId uint64) error

MarkAsRead 标记通知为已读

Types

type Entity

type Entity struct {
	Id        uint64              `gorm:"primaryKey;column:id;autoIncrement;not null;" json:"id"`
	UserId    uint64              `gorm:"column:user_id;type:bigint;index;" json:"userId"`                    // 接收通知的用户ID
	Payload   NotificationPayload `gorm:"column:payload;type:json;" json:"payload"`                           // 通知内容(JSON)
	EventType string              `gorm:"column:event_type;type:varchar(50);index;" json:"eventType"`         // 通知类型
	IsRead    bool                `gorm:"column:is_read;type:boolean;default:false;index;" json:"isRead"`     // 是否已读
	ReadAt    *time.Time          `gorm:"column:read_at;type:timestamp;null;" json:"readAt"`                  // 读取时间
	CreatedAt time.Time           `gorm:"column:created_at;index;autoCreateTime;<-:create;" json:"createdAt"` // 创建时间
	UpdatedAt time.Time           `gorm:"column:updated_at;autoUpdateTime;" json:"updatedAt"`                 // 更新时间
}

func GetByUserId

func GetByUserId(userId uint64, limit, offset int, unreadOnly bool) (notifications []*Entity, total int64, err error)

GetByUserId 获取用户的通知列表

func GetLastUnread added in v0.0.3

func GetLastUnread(userId uint64) (entity Entity)

GetLastUnread 获取用户未读通知数量

func QueryByUserId added in v0.0.3

func QueryByUserId(userId uint64, limit, startId int, unreadOnly bool) (notifications []*Entity, err error)

QueryByUserId 获取用户的通知列表

func (*Entity) TableName

func (itself *Entity) TableName() string

type NotificationPayload

type NotificationPayload struct {
	Title   string `json:"title"`   // 通知标题
	Content string `json:"content"` // 通知内容
	// 通用字段
	ActorId   uint64 `json:"actorId"`             // 触发者ID
	ActorName string `json:"actorName,omitempty"` // 触发者名称
	// 文章相关
	ArticleId    uint64 `json:"articleId,omitempty"`    // 相关文章ID
	ArticleTitle string `json:"articleTitle,omitempty"` // 文章标题
	// 评论相关
	CommentId uint64 `json:"commentId,omitempty"` // 评论ID
	// 其他元数据
	Extra map[string]interface{} `json:"metadata,omitempty"`
}

NotificationPayload 通知内容的基础结构

func (*NotificationPayload) Scan

func (p *NotificationPayload) Scan(value interface{}) error

Scan 实现 sql.Scanner 接口

func (NotificationPayload) Value

func (p NotificationPayload) Value() (driver.Value, error)

Value 实现 driver.Valuer 接口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL