models

package
v0.0.0-...-973246e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package models/models.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	Base
	UserID         uint      `json:"user_id"`
	OrganizationID uint      `json:"organization_id"`
	Key            string    `gorm:"unique" json:"key"`
	Name           string    `json:"name"`
	Permissions    []string  `json:"permissions" gorm:"type:jsonb"`
	ExpiresAt      time.Time `json:"expires_at"`
	LastUsedAt     time.Time `json:"last_used_at"`
}

APIKey represents an API key for authentication

func (*APIKey) BeforeCreate

func (k *APIKey) BeforeCreate(tx *gorm.DB) error

BeforeCreate is a GORM hook that runs before creating a new API key

type ActivityLog

type ActivityLog struct {
	Base
	UserID         uint      `json:"user_id"`
	OrganizationID uint      `json:"organization_id"`
	ActivityType   string    `json:"activity_type"`
	Timestamp      time.Time `json:"timestamp"`
	Metadata       JSONMap   `json:"metadata" gorm:"type:jsonb"`
}

ActivityLog represents user activity log

type AuditLog

type AuditLog struct {
	Base
	UserID       uint         `json:"user_id"`
	Action       string       `json:"action"`
	ResourceType string       `json:"resource_type"`
	ResourceID   uint         `json:"resource_id"`
	Timestamp    time.Time    `json:"timestamp"`
	Changes      JSONMap      `json:"changes" gorm:"type:jsonb"`
	Organization Organization `gorm:"foreignKey:OrganizationID" json:"organization"`
}

AuditLog represents an audit log entry

type Base

type Base struct {
	ID        uint           `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

Base contains common fields for all models

type Domain

type Domain struct {
	Base
	OrganizationID uint   `json:"organization_id"`
	Domain         string `gorm:"unique" json:"domain"`
	Verified       bool   `json:"verified"`
}

Domain represents a custom domain for an organization

type Feature

type Feature struct {
	Base
	Name        string `json:"name"`
	Description string `json:"description"`
}

Feature represents a specific feature of a subscription plan

type JSONMap

type JSONMap map[string]interface{}

JSONMap is a type for storing JSON data in the database

type NotificationPreference

type NotificationPreference struct {
	Base
	UserID          uint `json:"user_id"`
	EmailEnabled    bool `json:"email_enabled"`
	SMSEnabled      bool `json:"sms_enabled"`
	InAppEnabled    bool `json:"in_app_enabled"`
	BillingEmails   bool `json:"billing_emails"`
	ProductEmails   bool `json:"product_emails"`
	MarketingEmails bool `json:"marketing_emails"`
}

NotificationPreference represents user notification preferences

type Organization

type Organization struct {
	Base
	Name             string               `json:"name"`
	Users            []User               `gorm:"many2many:user_organizations;" json:"users"`
	Subscriptions    []Subscription       `json:"subscriptions"`
	SubscriptionPlan SubscriptionPlan     `json:"subscription_plan"`
	Seats            []Seat               `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"seats"`
	Domains          []Domain             `gorm:"constraint:OnUpdate:CASCADE,OnDelete:SET NULL;" json:"domains"`
	Settings         OrganizationSettings `gorm:"embedded" json:"settings"`
	AuditLogs        []AuditLog           `json:"audit_logs"`
	ActivityLogs     []ActivityLog        `json:"activity_logs"`
	APIKeys          []APIKey             `json:"api_keys"`
	Workflows        []Workflow           `json:"workflows"`
}

Organization represents a company or group

type OrganizationSettings

type OrganizationSettings struct {
	LogoURL    string `json:"logo_url"`
	ThemeColor string `json:"theme_color"`
}

OrganizationSettings represents the settings for an organization

type PaymentTransaction

type PaymentTransaction struct {
	Base
	SubscriptionID uint      `json:"subscription_id"`
	Amount         float64   `json:"amount"`
	Currency       string    `json:"currency"`
	Status         string    `json:"status"`
	Gateway        string    `json:"gateway"`
	GatewayID      string    `json:"gateway_id"`
	Timestamp      time.Time `json:"timestamp"`
}

PaymentTransaction represents a payment transaction

type Permission

type Permission struct {
	Base
	Name        string `json:"name"`
	Description string `json:"description"`
}

Permission represents a specific action or resource access

type Report

type Report struct {
	Base
	Name           string    `json:"name"`
	Description    string    `json:"description"`
	Query          string    `json:"query"`
	OrganizationID uint      `json:"organization_id"`
	CreatorID      uint      `json:"creator_id"`
	Schedule       string    `json:"schedule"`
	Recipients     []string  `json:"recipients" gorm:"type:jsonb"`
	LastRunAt      time.Time `json:"last_run_at"`
}

Report represents a report definition

type Role

type Role struct {
	Base
	Name        string       `json:"name"`
	Permissions []Permission `gorm:"many2many:role_permissions;" json:"permissions"`
}

Role defines the access level and permissions for a user

type Seat

type Seat struct {
	Base
	OrganizationID uint       `json:"organization_id"`
	UserID         uint       `json:"user_id"`
	Roles          []Role     `gorm:"many2many:seat_roles;" json:"roles"`
	Status         SeatStatus `json:"status"`
}

Seat represents a user seat within an organization

type SeatStatus

type SeatStatus string

SeatStatus represents the status of a seat

const (
	UserRole                      = "user"
	AdminRole                     = "admin"
	SeatStatusActive   SeatStatus = "active"
	SeatStatusInactive SeatStatus = "inactive"
	SeatStatusInvited  SeatStatus = "invited"
)

type Subscription

type Subscription struct {
	Base
	OrganizationID   uint                 `json:"organization_id"`
	SubscriptionPlan SubscriptionPlan     `json:"subscription_plan"`
	Status           SubscriptionStatus   `json:"status"`
	StartDate        time.Time            `json:"start_date"`
	EndDate          time.Time            `json:"end_date"`
	Transactions     []PaymentTransaction `json:"transactions"`
	PaymentMethod    string               `json:"payment_method"`
	LastPaymentDate  time.Time            `json:"last_payment_date"`
	NextBillingDate  time.Time            `json:"next_billing_date"`
}

Subscription represents a subscription for an organization

func (*Subscription) BeforeCreate

func (s *Subscription) BeforeCreate(tx *gorm.DB) error

BeforeCreate is a GORM hook that runs before creating a new subscription

type SubscriptionPlan

type SubscriptionPlan struct {
	Base
	Name        string    `json:"name"`
	Description string    `json:"description"`
	Price       float64   `json:"price"`
	Currency    string    `json:"currency"`
	Interval    string    `json:"interval"`
	Features    []Feature `gorm:"many2many:subscription_plan_features;" json:"features"`
}

SubscriptionPlan represents a subscription plan with pricing and features

type SubscriptionStatus

type SubscriptionStatus string

SubscriptionStatus represents the status of a subscription

const (
	SubscriptionStatusActive   SubscriptionStatus = "active"
	SubscriptionStatusInactive SubscriptionStatus = "inactive"
	SubscriptionStatusTrialing SubscriptionStatus = "trialing"
	SubscriptionStatusCanceled SubscriptionStatus = "canceled"
)

type User

type User struct {
	Base
	Email             string                 `gorm:"unique" json:"email"`
	Password          string                 `json:"-"`
	PasswordHash      string                 `json:"-"`
	Name              string                 `json:"name"`
	Roles             []Role                 `gorm:"many2many:user_roles;" json:"roles"`
	Organizations     []Organization         `gorm:"many2many:user_organizations;" json:"organizations"`
	Seats             []Seat                 `json:"seats"`
	Permissions       []Permission           `gorm:"many2many:user_permissions;" json:"permissions"`
	VerificationCode  string                 `json:"-"`
	Verified          bool                   `json:"verified"`
	ActivityLogs      []ActivityLog          `json:"activity_logs"`
	NotificationPrefs NotificationPreference `gorm:"foreignKey:UserID" json:"notification_prefs"`
	Locale            string                 `json:"locale"`
	Timezone          string                 `json:"timezone"`
	Language          string                 `json:"language"`
}

User represents a user in the system

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

BeforeCreate is a GORM hook that runs before creating a new user

func (*User) BeforeUpdate

func (u *User) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate is a GORM hook that runs before updating a user

type Workflow

type Workflow struct {
	Base
	Name           string         `json:"name"`
	Description    string         `json:"description"`
	Steps          []WorkflowStep `json:"steps" gorm:"type:jsonb"`
	OrganizationID uint           `json:"organization_id"`
	CreatorID      uint           `json:"creator_id"`
	Enabled        bool           `json:"enabled"`
}

Workflow represents a workflow process

type WorkflowStep

type WorkflowStep struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Order       int    `json:"order"`
	Approver    string `json:"approver"`
	Conditions  string `json:"conditions"`
}

WorkflowStep represents a step in a workflow process

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL