veza/veza-backend-api/internal/core/social/group_models.go

88 lines
3.3 KiB
Go

package social
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// Group represents a social group that users can create and join
type Group struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
Name string `gorm:"not null;size:255" json:"name"`
Description string `gorm:"type:text" json:"description"`
CreatorID uuid.UUID `gorm:"type:uuid;not null;index" json:"creator_id"`
AvatarURL string `gorm:"size:500" json:"avatar_url,omitempty"`
IsPublic bool `gorm:"default:true" json:"is_public"`
MemberCount int `gorm:"default:1" json:"member_count"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
func (g *Group) BeforeCreate(tx *gorm.DB) (err error) {
if g.ID == uuid.Nil {
g.ID = uuid.New()
}
return
}
// GroupMember represents a user's membership in a group
type GroupMember struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
GroupID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:idx_group_member" json:"group_id"`
UserID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:idx_group_member" json:"user_id"`
Role string `gorm:"default:'member';size:50" json:"role"` // "admin", "moderator", "member"
JoinedAt time.Time `gorm:"autoCreateTime" json:"joined_at"`
}
func (gm *GroupMember) BeforeCreate(tx *gorm.DB) (err error) {
if gm.ID == uuid.Nil {
gm.ID = uuid.New()
}
return
}
// GroupJoinRequest represents a user's request to join a private group (v0.302 S2.1)
type GroupJoinRequest struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
GroupID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:idx_group_join_request" json:"group_id"`
UserID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:idx_group_join_request" json:"user_id"`
Status string `gorm:"default:'pending';size:20" json:"status"` // pending, approved, rejected
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (gjr *GroupJoinRequest) BeforeCreate(tx *gorm.DB) (err error) {
if gjr.ID == uuid.Nil {
gjr.ID = uuid.New()
}
return
}
// TableName overrides the table name for GroupJoinRequest
func (GroupJoinRequest) TableName() string {
return "group_join_requests"
}
// GroupInvitation represents an invitation to join a group (v0.302 S2.2)
type GroupInvitation struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
GroupID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:idx_group_invitation" json:"group_id"`
InviterID uuid.UUID `gorm:"type:uuid;not null" json:"inviter_id"`
InviteeID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:idx_group_invitation" json:"invitee_id"`
Status string `gorm:"default:'pending';size:20" json:"status"` // pending, accepted, declined
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
func (gi *GroupInvitation) BeforeCreate(tx *gorm.DB) (err error) {
if gi.ID == uuid.Nil {
gi.ID = uuid.New()
}
return
}
// TableName overrides the table name for GroupInvitation
func (GroupInvitation) TableName() string {
return "group_invitations"
}