feat: 帖子收藏与用户关注

- 新增收藏功能:favorite 服务与 handler、FavoriteButton 组件
- 新增关注功能:follow 服务与 handler、FollowButton 组件
- 用户主页适配关注/粉丝与收藏展示
- flash 消息工具、广告与侧边栏组件微调
This commit is contained in:
2026-09-26 03:02:40 +08:00
parent 31f5360c26
commit d7c6b3a961
40 changed files with 1528 additions and 268 deletions

View File

@@ -57,7 +57,7 @@ func InitDB(dsn string) error {
if err := db.AutoMigrate(
&TemporaryUpload{}, &ModuleConfig{}, &SettingsAudit{}, &ActionCounter{}, &MailTask{}, &EmailChallenge{}, &StoredObject{},
&User{}, &Board{}, &Post{}, &PostEditHistory{}, &Comment{}, &CommentEditHistory{}, &RefreshToken{}, &Like{}, &Notification{}, &Checkin{},
&User{}, &Board{}, &Post{}, &PostEditHistory{}, &Comment{}, &CommentEditHistory{}, &RefreshToken{}, &Like{}, &Favorite{}, &Follow{}, &Notification{}, &Checkin{},
&Announcement{}, &SitePage{}, &SiteSetting{}, &SiteDailyStats{}, &SiteDailyVisitor{}, &VisitEvent{}, &Attachment{}, &UserBoard{}, &LoginLog{},
&ChatRoom{}, &ChatRoomMember{}, &ChatMessage{},
&PointLedger{}, &PostContentUnlock{}, &PostAttachment{}, &PostAttachmentUnlock{},

View File

@@ -432,6 +432,22 @@ type Like struct {
CreatedAt time.Time `json:"created_at"`
}
// Favorite 收藏记录(联合唯一索引防止重复收藏;无计数列,按钮仅表示状态)
type Favorite struct {
ID uint `gorm:"primaryKey" json:"id"`
PostID uint `gorm:"uniqueIndex:idx_fav_post_user;not null" json:"post_id"`
UserID uint `gorm:"uniqueIndex:idx_fav_post_user;not null" json:"user_id"`
CreatedAt time.Time `json:"created_at"`
}
// Follow 关注关系(FollowerID 关注了 FollowingID;联合唯一防止重复关注)
type Follow struct {
ID uint `gorm:"primaryKey" json:"id"`
FollowerID uint `gorm:"uniqueIndex:idx_follow_pair,priority:1;index;not null" json:"follower_id"`
FollowingID uint `gorm:"uniqueIndex:idx_follow_pair,priority:2;index;not null" json:"following_id"`
CreatedAt time.Time `json:"created_at"`
}
// Checkin 每日签到记录(用户+日期联合唯一,防止重复签到)
type Checkin struct {
ID uint `gorm:"primaryKey" json:"id"`
@@ -453,6 +469,7 @@ const (
NotificationTypeBadge = "badge" // 获得管理员颁发的徽章
NotificationTypeDeleted = "deleted" // 帖子被管理员删除
NotificationTypeNecroReply = "necro_reply" // 回复旧帖提醒(系统,ActorID=0)
NotificationTypeFollow = "follow" // 关注了你
)
// Notification 站内通知