model

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinTitleLength       = 3
	MaxTitleLength       = 100
	MaxDescriptionLength = 500
)

Variables

View Source
var (
	// ErrFormTitleRequired is returned when a form is created without a title
	ErrFormTitleRequired = errors.New("form title is required")

	// ErrFormSchemaRequired is returned when a form is created without a schema
	ErrFormSchemaRequired = errors.New("form schema is required")

	// ErrFormNotFound is returned when a form cannot be found
	ErrFormNotFound = errors.New("form not found")

	// ErrFormInvalid is returned when a form is invalid
	ErrFormInvalid = errors.New("form is invalid")

	// ErrSubmissionNotFound is returned when a form submission cannot be found
	ErrSubmissionNotFound = errors.New("form submission not found")
)

Functions

This section is empty.

Types

type Form added in v0.1.5

type Form struct {
	ID          string         `json:"id" gorm:"column:uuid;primaryKey;type:uuid;default:gen_random_uuid()"`
	UserID      string         `json:"user_id" gorm:"not null;index;type:uuid"`
	Title       string         `json:"title" gorm:"not null;size:100"`
	Description string         `json:"description" gorm:"size:500"`
	Schema      JSON           `json:"schema" gorm:"type:jsonb;not null"`
	Active      bool           `json:"active" gorm:"not null;default:true"`
	CreatedAt   time.Time      `json:"created_at" gorm:"not null;autoCreateTime"`
	UpdatedAt   time.Time      `json:"updated_at" gorm:"not null;autoUpdateTime"`
	DeletedAt   gorm.DeletedAt `json:"-" gorm:"index"`
}

Form represents a form in the system

func NewForm added in v0.1.5

func NewForm(userID, title, description string, schema JSON) *Form

NewForm creates a new form instance

func (*Form) Activate added in v0.1.5

func (f *Form) Activate()

Activate marks the form as active

func (*Form) BeforeCreate added in v0.1.5

func (f *Form) BeforeCreate(tx *gorm.DB) error

BeforeCreate is a GORM hook that runs before creating a form

func (*Form) BeforeUpdate added in v0.1.5

func (f *Form) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate is a GORM hook that runs before updating a form

func (*Form) Deactivate added in v0.1.5

func (f *Form) Deactivate()

Deactivate marks the form as inactive

func (*Form) TableName added in v0.1.5

func (f *Form) TableName() string

TableName specifies the table name for the Form model

func (*Form) Update added in v0.1.5

func (f *Form) Update(title, description string, schema JSON)

Update updates the form with new values

func (*Form) Validate added in v0.1.5

func (f *Form) Validate() error

Validate validates the form

type FormSubmission

type FormSubmission struct {
	ID          string           `json:"id"`
	FormID      string           `json:"form_id"`
	Data        JSON             `json:"data"`
	SubmittedAt time.Time        `json:"submitted_at"`
	Status      SubmissionStatus `json:"status"`
	Metadata    JSON             `json:"metadata"`
}

FormSubmission represents a form submission

func (*FormSubmission) AddMetadata

func (s *FormSubmission) AddMetadata(key, value string)

AddMetadata adds metadata to the submission

func (*FormSubmission) GetMetadata

func (s *FormSubmission) GetMetadata(key string) string

GetMetadata returns the metadata value for a key

func (*FormSubmission) UpdateStatus

func (s *FormSubmission) UpdateStatus(status SubmissionStatus)

UpdateStatus updates the submission status

func (*FormSubmission) Validate

func (s *FormSubmission) Validate() error

Validate validates the form submission

type JSON added in v0.1.5

type JSON map[string]any

JSON is a type alias for map[string]any to represent JSON data

func (*JSON) Scan added in v0.1.5

func (j *JSON) Scan(value any) error

Scan implements the sql.Scanner interface for JSON

func (*JSON) Value added in v0.1.5

func (j *JSON) Value() (driver.Value, error)

Value implements the driver.Valuer interface for JSON

type SubmissionStatus

type SubmissionStatus string

SubmissionStatus represents the status of a form submission

const (
	// SubmissionStatusPending indicates the submission is pending processing
	SubmissionStatusPending SubmissionStatus = "pending"
	// SubmissionStatusProcessing indicates the submission is being processed
	SubmissionStatusProcessing SubmissionStatus = "processing"
	// SubmissionStatusCompleted indicates the submission has been processed successfully
	SubmissionStatusCompleted SubmissionStatus = "completed"
	// SubmissionStatusFailed indicates the submission processing failed
	SubmissionStatusFailed SubmissionStatus = "failed"
)

Jump to

Keyboard shortcuts

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