38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// RoomInvitation represents an invitation to join a room (v0.9.7)
|
|
type RoomInvitation struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
|
RoomID uuid.UUID `gorm:"type:uuid;not null" json:"room_id"`
|
|
InviterID uuid.UUID `gorm:"type:uuid;not null" json:"inviter_id"`
|
|
InviteeID *uuid.UUID `gorm:"type:uuid" json:"invitee_id,omitempty"`
|
|
Token uuid.UUID `gorm:"type:uuid;not null;uniqueIndex" json:"token"`
|
|
Status string `gorm:"type:varchar(20);not null;default:'pending'" json:"status"` // pending, accepted, expired
|
|
ExpiresAt time.Time `gorm:"not null" json:"expires_at"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
|
|
|
Room Room `gorm:"foreignKey:RoomID" json:"-"`
|
|
Inviter User `gorm:"foreignKey:InviterID" json:"-"`
|
|
}
|
|
|
|
func (r *RoomInvitation) BeforeCreate(tx *gorm.DB) error {
|
|
if r.ID == uuid.Nil {
|
|
r.ID = uuid.New()
|
|
}
|
|
if r.Token == uuid.Nil {
|
|
r.Token = uuid.New()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (RoomInvitation) TableName() string {
|
|
return "room_invitations"
|
|
}
|