lv8girl!
This commit is contained in:
84
internal/models/models.go
Normal file
84
internal/models/models.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
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"
|
||||
}
|
||||
Reference in New Issue
Block a user