mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 18:52:56 +00:00
69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package models
|
|
|
|
import "gorm.io/datatypes"
|
|
|
|
// PointsTransaction logs changes in points/xp
|
|
// Reason examples: comment_create, poll_vote, newsletter_subscribe, redeem, admin_adjust
|
|
// Meta can hold ids like {"comment_id":123}
|
|
|
|
type PointsTransaction struct {
|
|
BaseModel
|
|
UserID uint `json:"user_id" gorm:"index;not null"`
|
|
Delta int64 `json:"delta"`
|
|
XPDelta int64 `json:"xp_delta"`
|
|
Reason string `json:"reason" gorm:"size:64;index"`
|
|
Meta datatypes.JSONMap `json:"meta" gorm:"type:jsonb"`
|
|
}
|
|
|
|
func (PointsTransaction) TableName() string { return "points_transactions" }
|
|
|
|
// Achievement definition managed in DB for flexibility
|
|
// Condition is a code string handled by service (e.g., first_comment, first_vote, votes_10, comments_25)
|
|
|
|
type Achievement struct {
|
|
BaseModel
|
|
Code string `json:"code" gorm:"size:64;uniqueIndex"`
|
|
Title string `json:"title"`
|
|
Description string `json:"description"`
|
|
Points int64 `json:"points"`
|
|
XP int64 `json:"xp"`
|
|
Icon string `json:"icon"`
|
|
Active bool `json:"active" gorm:"default:true"`
|
|
}
|
|
|
|
func (Achievement) TableName() string { return "achievements" }
|
|
|
|
type UserAchievement struct {
|
|
BaseModel
|
|
UserID uint `json:"user_id" gorm:"index;not null"`
|
|
AchievementID uint `json:"achievement_id" gorm:"index;not null"`
|
|
}
|
|
|
|
func (UserAchievement) TableName() string { return "user_achievements" }
|
|
|
|
// Reward items configured by admin (e.g., avatars, merch vouchers)
|
|
|
|
type RewardItem struct {
|
|
BaseModel
|
|
Name string `json:"name"`
|
|
Type string `json:"type" gorm:"size:32;index"` // avatar_static, avatar_animated, merch_coupon, custom
|
|
CostPoints int64 `json:"cost_points"`
|
|
ImageURL string `json:"image_url"`
|
|
Stock int `json:"stock"`
|
|
Active bool `json:"active" gorm:"default:true"`
|
|
Metadata datatypes.JSONMap `json:"metadata" gorm:"type:jsonb"`
|
|
}
|
|
|
|
func (RewardItem) TableName() string { return "reward_items" }
|
|
|
|
// Redemption log for rewards
|
|
|
|
type RewardRedemption struct {
|
|
BaseModel
|
|
UserID uint `json:"user_id" gorm:"index;not null"`
|
|
RewardID uint `json:"reward_id" gorm:"index;not null"`
|
|
Status string `json:"status" gorm:"size:24;default:'pending';index"`
|
|
}
|
|
|
|
func (RewardRedemption) TableName() string { return "reward_redemptions" }
|