feat: 收藏夹系统 + Studio 趋势图 + 通知偏好设置
- 新增收藏夹系统 (Folder/FolderItem 模型、CRUD API、前端管理页) - 新增文章详情页收藏按钮 (书签图标、ToggleFavorite 一键收藏) - 新增 Studio 趋势图 (赋能值/评论/点赞/收藏 4 线图, 7d/30d/90d) - 新增通知偏好设置页 (评论/回复/点赞/关注 4 类开关) - 后端通知列表支持按偏好过滤 (排除已关闭的通知类型) - 下载 Chart.js 到本地静态资源 (static/js/chart.umd.min.js) - 补充收藏夹卡片、开关滑块、趋势图网格等 CSS 样式
This commit is contained in:
@ -105,3 +105,43 @@ func (r *NotificationRepo) GetUsernameByID(userID uint) (string, error) {
|
||||
err := r.db.Select("username").First(&user, userID).Error
|
||||
return user.Username, err
|
||||
}
|
||||
|
||||
// GetNotifyPrefs 获取用户通知偏好(NotifyPrefs 字段原始 JSON)
|
||||
func (r *NotificationRepo) GetNotifyPrefs(userID uint) (string, error) {
|
||||
var prefs string
|
||||
err := r.db.Table("users").Select("notify_prefs").Where("uid = ?", userID).Scan(&prefs).Error
|
||||
return prefs, err
|
||||
}
|
||||
|
||||
// ListByUserExcludeTypes 分页查询用户消息(排除指定通知类型)
|
||||
func (r *NotificationRepo) ListByUserExcludeTypes(userID uint, excludeTypes []string, offset, limit int) ([]model.Notification, error) {
|
||||
var list []model.Notification
|
||||
q := r.db.Where("user_id = ?", userID)
|
||||
if len(excludeTypes) > 0 {
|
||||
q = q.Where("notify_type NOT IN ?", excludeTypes)
|
||||
}
|
||||
err := q.Order("created_at DESC").Offset(offset).Limit(limit).Find(&list).Error
|
||||
return list, err
|
||||
}
|
||||
|
||||
// CountByUserExcludeTypes 统计用户消息总数(排除指定通知类型)
|
||||
func (r *NotificationRepo) CountByUserExcludeTypes(userID uint, excludeTypes []string) (int64, error) {
|
||||
var count int64
|
||||
q := r.db.Model(&model.Notification{}).Where("user_id = ?", userID)
|
||||
if len(excludeTypes) > 0 {
|
||||
q = q.Where("notify_type NOT IN ?", excludeTypes)
|
||||
}
|
||||
err := q.Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
// CountUnreadExcludeTypes 统计用户未读消息数(排除指定通知类型)
|
||||
func (r *NotificationRepo) CountUnreadExcludeTypes(userID uint, excludeTypes []string) (int64, error) {
|
||||
var count int64
|
||||
q := r.db.Model(&model.Notification{}).Where("user_id = ? AND is_read = false", userID)
|
||||
if len(excludeTypes) > 0 {
|
||||
q = q.Where("notify_type NOT IN ?", excludeTypes)
|
||||
}
|
||||
err := q.Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user