Files
lv8girl/internal/models/models.go
nannanwu 690b4d5961 fix(admin): 添加管理操作错误处理及更新模板样式
- 管理后台帖子与用户审核操作中添加失败错误重定向处理
- 管理后台帖子、用户、评论删除操作中添加错误检查及提示
- 用户角色更新操作失败时添加错误重定向
- 用户封禁通知失败时添加相应错误提示
- 登录登出时session保存加入错误处理
- 讨论区上传目录创建失败时显示错误提示
- 移除admin_dashboard.html多余样式及修正侧边栏当前页高亮
- admin_posts.html和admin_users.html添加状态样式动态使用的隐藏span元素
- admin_users.html为角色选择添加label以提升无障碍性
- 升级项目依赖版本,包含gin、gorm、validator等核心库版本更新
2026-02-24 21:14:55 +08:00

86 lines
3.1 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
type User struct {
//goland:noinspection SpellCheckingInspection
ID uint `gorm:"primaryKey" json:"id"`
Username string `gorm:"size:50;uniqueIndex;not null" json:"username"`
Email string `gorm:"size:100;uniqueIndex;not null" json:"email"`
PasswordHash string `gorm:"size:255;not null" json:"-"`
Avatar string `gorm:"size:255" json:"avatar"`
Role string `gorm:"size:20;default:user" json:"role"`
Status string `gorm:"size:20;default:pending" json:"status"`
LastActive *time.Time `json:"last_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (User) TableName() string {
return "users"
}
type Discussion struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"not null;index" json:"user_id"`
User User `gorm:"foreignKey:UserID" json:"user"`
Title string `gorm:"size:200;not null" json:"title"`
Content string `gorm:"type:text;not null" json:"content"`
ImagePath string `gorm:"size:255" json:"image_path"`
Status string `gorm:"size:20;default:pending" json:"status"`
Views int `gorm:"default:0" json:"views"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (Discussion) TableName() string {
return "discussions"
}
type Comment struct {
ID uint `gorm:"primaryKey" json:"id"`
PostID uint `gorm:"not null;index" json:"post_id"`
UserID uint `gorm:"not null;index" json:"user_id"`
User User `gorm:"foreignKey:UserID" json:"user"`
Content string `gorm:"type:text;not null" json:"content"`
CreatedAt time.Time `json:"created_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (Comment) TableName() string {
return "comments"
}
type Like struct {
ID uint `gorm:"primaryKey" json:"id"`
PostID uint `gorm:"not null;uniqueIndex:idx_post_user" json:"post_id"`
UserID uint `gorm:"not null;uniqueIndex:idx_post_user" json:"user_id"`
CreatedAt time.Time `json:"created_at"`
}
func (Like) TableName() string {
return "likes"
}
type PrivateMessage struct {
ID uint `gorm:"primaryKey" json:"id"`
FromUserID uint `gorm:"not null;index" json:"from_user_id"`
FromUser User `gorm:"foreignKey:FromUserID" json:"from_user"`
ToUserID uint `gorm:"not null;index" json:"to_user_id"`
ToUser User `gorm:"foreignKey:ToUserID" json:"to_user"`
Content string `gorm:"type:text;not null" json:"content"`
IsRead bool `gorm:"default:false" json:"is_read"`
CreatedAt time.Time `json:"created_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (PrivateMessage) TableName() string {
return "private_messages"
}