initial rebuild

This commit is contained in:
allanice001
2025-09-01 13:34:13 +01:00
commit 95bd9615d1
100 changed files with 12440 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package models
import (
"time"
"gorm.io/gorm"
)
type Timestamped struct {
CreatedAt time.Time `gorm:"column:created_at;not null;default:now()" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime;column:updated_at;not null;default:now()" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}

View File

@@ -0,0 +1,21 @@
package models
import (
"time"
"github.com/google/uuid"
)
type EmailVerification struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"`
User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
Token string `gorm:"type:char(43);uniqueIndex;not null" json:"-"`
ExpiresAt time.Time `gorm:"not null;index" json:"expires_at"`
Used bool `gorm:"not null;default:false;index" json:"used"`
Timestamped
}
func (e EmailVerification) IsActive(now time.Time) bool {
return !e.Used && now.Before(e.ExpiresAt)
}

View File

@@ -0,0 +1,19 @@
package models
import (
"time"
"github.com/google/uuid"
)
type Invitation struct {
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey"`
OrganizationID uuid.UUID `gorm:"type:uuid;not null"`
Organization Organization `gorm:"foreignKey:OrganizationID;constraint:OnDelete:CASCADE" json:"organization"`
Email string `gorm:"type:text;not null"`
Role string `gorm:"type:text;default:'member';not null"`
Status string `gorm:"type:text;default:'pending';not null"` // pending, accepted, revoked
ExpiresAt time.Time `gorm:"not null"`
InviterID uuid.UUID `gorm:"type:uuid;not null"`
Timestamped
}

View File

@@ -0,0 +1,21 @@
package models
import "github.com/google/uuid"
type MemberRole string
const (
MemberRoleAdmin MemberRole = "admin"
MemberRoleMember MemberRole = "member"
MemberRoleUser MemberRole = "user"
)
type Member struct {
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null" json:"user_id"`
User User `gorm:"foreignKey:UserID" json:"user"`
OrganizationID uuid.UUID `gorm:"type:uuid;not null" json:"organization_id"`
Organization Organization `gorm:"foreignKey:OrganizationID;constraint:OnDelete:CASCADE" json:"organization"`
Role MemberRole `gorm:"not null;default:member" json:"role"` // e.g. admin, member
Timestamped
}

View File

@@ -0,0 +1,12 @@
package models
import "github.com/google/uuid"
type Organization struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
Name string `gorm:"not null" json:"name"`
Slug string `gorm:"unique" json:"slug"`
Logo string `json:"logo"`
Metadata string `json:"metadata"`
Timestamped
}

View File

@@ -0,0 +1,21 @@
package models
import (
"time"
"github.com/google/uuid"
)
type PasswordReset struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"`
User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
Token string `gorm:"type:char(43);uniqueIndex;not null" json:"-"`
ExpiresAt time.Time `gorm:"not null;index" json:"expires_at"`
Used bool `gorm:"not null;default:false;index" json:"used"`
Timestamped
}
func (p PasswordReset) IsActive(now time.Time) bool {
return !p.Used && now.Before(p.ExpiresAt)
}

View File

@@ -0,0 +1,15 @@
package models
import (
"time"
"github.com/google/uuid"
)
type RefreshToken struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
UserID uuid.UUID
Token string `gorm:"uniqueIndex"`
ExpiresAt time.Time
Revoked bool
}

View File

@@ -0,0 +1,33 @@
package models
import (
"time"
"github.com/google/uuid"
)
type Role string
const (
RoleAdmin Role = "admin"
RoleUser Role = "user"
)
type User struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
Name string `gorm:"type:varchar(255);not null" json:"name"`
Email string `gorm:"uniqueIndex" json:"email"`
EmailVerified bool `gorm:"default:false" json:"email_verified"`
EmailVerifiedAt time.Time `gorm:"default:null" json:"email_verified_at"`
Password string
Role Role
Timestamped
}
func (r Role) IsValid() bool {
switch r {
case RoleAdmin, RoleUser:
return true
}
return false
}