Set up project files and add .gitignore to exclude local build/runtime artifacts. Made-with: Cursor
39 lines
937 B
Go
39 lines
937 B
Go
package model
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"carrot_bbs/internal/pkg/utils"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// GroupAnnouncement 群公告模型
|
|
type GroupAnnouncement struct {
|
|
ID string `gorm:"primaryKey;size:20" json:"id"`
|
|
GroupID string `gorm:"not null;index" json:"group_id"`
|
|
Content string `gorm:"type:text;not null" json:"content"`
|
|
AuthorID string `gorm:"type:varchar(36);not null" json:"author_id"`
|
|
IsPinned bool `gorm:"default:false" json:"is_pinned"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// BeforeCreate 创建前生成雪花算法ID
|
|
func (ga *GroupAnnouncement) BeforeCreate(tx *gorm.DB) error {
|
|
if ga.ID == "" {
|
|
id, err := utils.GetSnowflake().GenerateID()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ga.ID = strconv.FormatInt(id, 10)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (GroupAnnouncement) TableName() string {
|
|
return "group_announcements"
|
|
}
|