首次提交
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// Achievement 成就徽章
|
||||
type Achievement struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(50)" json:"id"`
|
||||
Name string `gorm:"type:varchar(100);not null" json:"name"`
|
||||
Description *string `gorm:"type:varchar(200)" json:"description,omitempty"`
|
||||
Icon *string `gorm:"type:varchar(50)" json:"icon,omitempty"`
|
||||
Rarity string `gorm:"default:bronze;type:varchar(20)" json:"rarity"`
|
||||
Condition *string `gorm:"type:varchar(200)" json:"condition,omitempty"`
|
||||
|
||||
Users []UserAchievement `gorm:"foreignKey:AchievementID" json:"-"`
|
||||
}
|
||||
|
||||
func (Achievement) TableName() string { return "achievements" }
|
||||
|
||||
// UserAchievement 用户成就关联
|
||||
type UserAchievement struct {
|
||||
UserID string `gorm:"column:user_id;type:varchar(32);not null;primaryKey"`
|
||||
AchievementID string `gorm:"column:achievement_id;type:varchar(50);not null;primaryKey"`
|
||||
UnlockedAt time.Time `gorm:"column:unlocked_at"`
|
||||
|
||||
User User `gorm:"foreignKey:UserID" json:"-"`
|
||||
Achievement Achievement `gorm:"foreignKey:AchievementID" json:"-"`
|
||||
}
|
||||
|
||||
func (UserAchievement) TableName() string { return "user_achievements" }
|
||||
@@ -0,0 +1,33 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// AdminRole 管理员角色
|
||||
type AdminRole string
|
||||
|
||||
const (
|
||||
RoleSuperAdmin AdminRole = "super_admin"
|
||||
RoleAdmin AdminRole = "admin"
|
||||
)
|
||||
|
||||
// AdminStatus 管理员状态
|
||||
type AdminStatus string
|
||||
|
||||
const (
|
||||
AdminStatusActive AdminStatus = "active"
|
||||
AdminStatusDisabled AdminStatus = "disabled"
|
||||
)
|
||||
|
||||
// Admin 管理员模型
|
||||
type Admin struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(32)" json:"id"`
|
||||
Username string `gorm:"uniqueIndex;type:varchar(50);not null" json:"username"`
|
||||
PasswordHash string `gorm:"column:password_hash;type:varchar(255);not null" json:"-"`
|
||||
Nickname *string `gorm:"type:varchar(50)" json:"nickname,omitempty"`
|
||||
Role AdminRole `gorm:"default:admin;type:varchar(20)" json:"role"`
|
||||
Status AdminStatus `gorm:"default:active;type:varchar(20)" json:"status"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Admin) TableName() string { return "admins" }
|
||||
@@ -0,0 +1,78 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// CheckInCategory 打卡分类
|
||||
type CheckInCategory string
|
||||
|
||||
const (
|
||||
CategoryStudy CheckInCategory = "study"
|
||||
CategoryHealth CheckInCategory = "health"
|
||||
CategoryHabit CheckInCategory = "habit"
|
||||
CategoryHobby CheckInCategory = "hobby"
|
||||
CategoryGoal CheckInCategory = "goal"
|
||||
)
|
||||
|
||||
// CycleType 打卡周期
|
||||
type CycleType string
|
||||
|
||||
const (
|
||||
CycleDaily CycleType = "daily"
|
||||
CycleWeekly CycleType = "weekly"
|
||||
CycleEveryOther CycleType = "every_other_day"
|
||||
CycleCustom CycleType = "custom"
|
||||
)
|
||||
|
||||
// ItemStatus 打卡项状态
|
||||
type ItemStatus string
|
||||
|
||||
const (
|
||||
StatusActive ItemStatus = "active"
|
||||
StatusPaused ItemStatus = "paused"
|
||||
StatusArchived ItemStatus = "archived"
|
||||
StatusDeleted ItemStatus = "deleted"
|
||||
)
|
||||
|
||||
// RecordStatus 打卡记录状态
|
||||
type RecordStatus string
|
||||
|
||||
const (
|
||||
RecordNormal RecordStatus = "normal"
|
||||
RecordMakeup RecordStatus = "makeup"
|
||||
)
|
||||
|
||||
// CheckInItem 打卡项
|
||||
type CheckInItem struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(32)" json:"id"`
|
||||
UserID string `gorm:"column:user_id;type:varchar(32);not null;index" json:"userId"`
|
||||
Name string `gorm:"type:varchar(100);not null" json:"name"`
|
||||
Icon *string `gorm:"type:varchar(50)" json:"icon,omitempty"`
|
||||
Category CheckInCategory `gorm:"type:varchar(20);not null" json:"category"`
|
||||
DailyGoal *string `gorm:"column:daily_goal;type:varchar(200)" json:"dailyGoal,omitempty"`
|
||||
CycleType CycleType `gorm:"column:cycle_type;default:daily;type:varchar(20)" json:"cycleType"`
|
||||
Privacy PrivacyLevel `gorm:"default:2" json:"privacy"`
|
||||
Status ItemStatus `gorm:"default:active;type:varchar(20)" json:"status"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
||||
|
||||
User User `gorm:"foreignKey:UserID" json:"-"`
|
||||
Records []CheckInRecord `gorm:"foreignKey:ItemID" json:"-"`
|
||||
}
|
||||
|
||||
func (CheckInItem) TableName() string { return "checkin_items" }
|
||||
|
||||
// CheckInRecord 打卡记录
|
||||
type CheckInRecord struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(32)" json:"id"`
|
||||
ItemID string `gorm:"column:item_id;type:varchar(32);not null;index" json:"itemId"`
|
||||
UserID string `gorm:"column:user_id;type:varchar(32);not null;index" json:"userId"`
|
||||
CheckDate time.Time `gorm:"column:check_date;not null;index" json:"checkDate"`
|
||||
Status RecordStatus `gorm:"default:normal;type:varchar(20)" json:"status"`
|
||||
Note *string `gorm:"type:varchar(500)" json:"note,omitempty"`
|
||||
Images *string `gorm:"type:text" json:"images,omitempty"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
||||
|
||||
Item CheckInItem `gorm:"foreignKey:ItemID" json:"-"`
|
||||
User User `gorm:"foreignKey:UserID" json:"-"`
|
||||
}
|
||||
|
||||
func (CheckInRecord) TableName() string { return "checkin_records" }
|
||||
@@ -0,0 +1,57 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// Post 动态
|
||||
type Post struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(32)" json:"id"`
|
||||
UserID string `gorm:"column:user_id;type:varchar(32);not null;index" json:"userId"`
|
||||
Content *string `gorm:"type:text" json:"content,omitempty"`
|
||||
Images *string `gorm:"type:text" json:"images,omitempty"`
|
||||
Privacy int `gorm:"default:1" json:"privacy"`
|
||||
Likes int `gorm:"default:0" json:"likes"`
|
||||
Comments int `gorm:"default:0" json:"comments"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
||||
|
||||
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
}
|
||||
|
||||
func (Post) TableName() string { return "posts" }
|
||||
|
||||
// Friend 好友关系
|
||||
type Friend struct {
|
||||
UserID string `gorm:"column:user_id;type:varchar(32);not null;primaryKey"`
|
||||
FriendID string `gorm:"column:friend_id;type:varchar(32);not null;primaryKey"`
|
||||
Status string `gorm:"default:pending;type:varchar(20)" json:"status"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
}
|
||||
|
||||
func (Friend) TableName() string { return "friends" }
|
||||
|
||||
// Group 打卡小组
|
||||
type Group struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(32)" json:"id"`
|
||||
Name string `gorm:"type:varchar(20);not null" json:"name"`
|
||||
Cover *string `gorm:"type:varchar(255)" json:"cover,omitempty"`
|
||||
Intro *string `gorm:"type:varchar(200)" json:"intro,omitempty"`
|
||||
Type string `gorm:"default:public;type:varchar(20)" json:"type"`
|
||||
MaxMember int `gorm:"column:max_member;default:50" json:"maxMember"`
|
||||
CreatedBy string `gorm:"column:created_by;type:varchar(32)" json:"createdBy"`
|
||||
CreatedAt time.Time `gorm:"column:created_at"`
|
||||
|
||||
Members []GroupMember `gorm:"foreignKey:GroupID" json:"-"`
|
||||
}
|
||||
|
||||
func (Group) TableName() string { return "groups" }
|
||||
|
||||
// GroupMember 小组成员
|
||||
type GroupMember struct {
|
||||
GroupID string `gorm:"column:group_id;type:varchar(32);not null;primaryKey"`
|
||||
UserID string `gorm:"column:user_id;type:varchar(32);not null;primaryKey"`
|
||||
Role string `gorm:"default:member;type:varchar(20)" json:"role"`
|
||||
JoinedAt time.Time `gorm:"column:joined_at"`
|
||||
|
||||
Group Group `gorm:"foreignKey:GroupID" json:"-"`
|
||||
}
|
||||
|
||||
func (GroupMember) TableName() string { return "group_members" }
|
||||
@@ -0,0 +1,33 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
// PrivacyLevel 隐私级别
|
||||
type PrivacyLevel int
|
||||
|
||||
const (
|
||||
PrivacyPublic PrivacyLevel = 1 // 公开
|
||||
PrivacyFriendsOnly PrivacyLevel = 2 // 仅好友可见
|
||||
PrivacyPrivate PrivacyLevel = 3 // 仅自己可见
|
||||
)
|
||||
|
||||
// User 用户模型
|
||||
type User struct {
|
||||
ID string `gorm:"primaryKey;type:varchar(32)" json:"id"`
|
||||
Phone *string `gorm:"uniqueIndex;type:varchar(20)" json:"phone,omitempty"`
|
||||
Nickname *string `gorm:"type:varchar(50)" json:"nickname,omitempty"`
|
||||
Avatar *string `gorm:"type:varchar(255)" json:"avatar,omitempty"`
|
||||
Bio *string `gorm:"type:varchar(100)" json:"bio,omitempty"`
|
||||
Motto *string `gorm:"type:varchar(50)" json:"motto,omitempty"`
|
||||
Privacy PrivacyLevel `gorm:"default:2" json:"privacy"`
|
||||
Points int `gorm:"default:0" json:"points"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
|
||||
|
||||
// 关联
|
||||
CheckInItems []CheckInItem `gorm:"foreignKey:UserID" json:"-"`
|
||||
Records []CheckInRecord `gorm:"foreignKey:UserID" json:"-"`
|
||||
Posts []Post `gorm:"foreignKey:UserID" json:"-"`
|
||||
}
|
||||
|
||||
func (User) TableName() string { return "users" }
|
||||
Reference in New Issue
Block a user