38 lines
1 KiB
Go
38 lines
1 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Session represents a user session
|
|
type Session struct {
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
|
UserID uuid.UUID `gorm:"not null;index" json:"user_id"`
|
|
Token string `gorm:"column:token_hash;uniqueIndex;not null" json:"-"`
|
|
IPAddress string `json:"ip_address"`
|
|
UserAgent string `json:"user_agent"`
|
|
// IsActive field removed - sessions table doesn't have this column
|
|
RevokedAt *time.Time `json:"revoked_at"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
// UpdatedAt and DeletedAt removed - sessions table doesn't have these columns
|
|
|
|
// Relations
|
|
User User `gorm:"foreignKey:UserID" json:"-"`
|
|
}
|
|
|
|
// BeforeCreate hook to generate UUID if not set
|
|
func (s *Session) BeforeCreate(tx *gorm.DB) error {
|
|
if s.ID == uuid.Nil {
|
|
s.ID = uuid.New()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// TableName returns the table name for the Session model
|
|
func (Session) TableName() string {
|
|
return "sessions"
|
|
}
|