Files
backend/internal/model/group.go
lafay 2f584c1f2c
All checks were successful
Build Backend / build (push) Successful in 5m10s
Build Backend / build-docker (push) Successful in 2m22s
This is a breaking change that renames the entire project from "Carrot BBS" to "WithYou".
The Go module name has been changed from `carrot_bbs` to `with_you`, which requires
all import paths to be updated throughout the codebase and by external consumers.

BREAKING CHANGE: Module name changed from carrot_bbs to with_you. All imports
and dependencies must be updated from carrot_bbs/* to with_you/*.
2026-04-22 16:01:59 +08:00

58 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package model
import (
"strconv"
"time"
"with_you/internal/pkg/utils"
"gorm.io/gorm"
)
// JoinType 群组加入类型
type JoinType int
const (
JoinTypeAnyone JoinType = 0 // 允许任何人加入
JoinTypeApproval JoinType = 1 // 需要审批
JoinTypeForbidden JoinType = 2 // 不允许加入
)
// Group 群组模型
type Group struct {
ID string `gorm:"primaryKey;size:20" json:"id"`
Name string `gorm:"size:50;not null" json:"name"`
Avatar string `gorm:"size:512" json:"avatar"`
Description string `gorm:"size:500" json:"description"`
OwnerID string `gorm:"type:varchar(36);not null;index" json:"owner_id"`
MemberCount int `gorm:"default:0" json:"member_count"`
MaxMembers int `gorm:"default:500" json:"max_members"`
JoinType JoinType `gorm:"default:0" json:"join_type"` // 0:允许任何人加入 1:需要审批 2:不允许加入
MuteAll bool `gorm:"default:false" json:"mute_all"` // 全员禁言
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// BeforeCreate 创建前生成雪花算法ID
func (g *Group) BeforeCreate(tx *gorm.DB) error {
if g.ID == "" {
id, err := utils.GetSnowflake().GenerateID()
if err != nil {
return err
}
g.ID = strconv.FormatInt(id, 10)
}
return nil
}
// GetIDInt 获取数字类型的ID用于比较
func (g *Group) GetIDInt() uint64 {
id, _ := strconv.ParseUint(g.ID, 10, 64)
return id
}
// TableName 指定表名
func (Group) TableName() string {
return "groups"
}