model

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package model contains domain models and error definitions for forms.

Package model contains domain models and error definitions for forms.

Package model contains domain models and error definitions for forms.

Index

Constants

View Source
const (
	// MinTitleLength is the minimum length for a form title
	MinTitleLength = 3
	// MaxTitleLength is the maximum length for a form title
	MaxTitleLength = 100
	// MaxDescriptionLength is the maximum length for a form description
	MaxDescriptionLength = 500
	// MaxFields is the maximum number of fields allowed in a form
	MaxFields = 50
)

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")
)
View Source
var (
	// ErrInvalidJSON represents an invalid JSON error
	ErrInvalidJSON = errors.New("invalid JSON")
)

Functions

This section is empty.

Types

type Field added in v0.1.5

type Field struct {
	ID        string    `json:"id" gorm:"primaryKey"`
	FormID    string    `json:"form_id" gorm:"not null"`
	Label     string    `json:"label" gorm:"size:100;not null"`
	Type      string    `json:"type" gorm:"size:20;not null"`
	Required  bool      `json:"required" gorm:"not null;default:false"`
	Options   []string  `json:"options" gorm:"type:json"`
	CreatedAt time.Time `json:"created_at" gorm:"not null"`
	UpdatedAt time.Time `json:"updated_at" gorm:"not null"`
}

Field represents a form field

func (*Field) Validate added in v0.1.5

func (f *Field) Validate() error

Validate validates the field

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"`
	Fields      []Field        `json:"fields" gorm:"foreignKey:FormID"`
	Status      string         `json:"status" gorm:"size:20;not null;default:'draft'"`

	// CORS settings for form embedding
	CorsOrigins JSON `json:"cors_origins" gorm:"type:json"`
	CorsMethods JSON `json:"cors_methods" gorm:"type:json"`
	CorsHeaders JSON `json:"cors_headers" gorm:"type:json"`
}

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(_ *gorm.DB) error

BeforeCreate is a GORM hook that runs before creating a form

func (*Form) BeforeSave added in v0.1.5

func (f *Form) BeforeSave(_ *gorm.DB) error

BeforeSave is a GORM hook that runs before saving a form

func (*Form) BeforeUpdate added in v0.1.5

func (f *Form) BeforeUpdate(_ *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) GetCorsConfig added in v0.1.5

func (f *Form) GetCorsConfig() (origins, methods, headers []string)

GetCorsConfig returns the CORS configuration for this form

func (*Form) GetID added in v0.1.5

func (f *Form) GetID() string

GetID returns the form's ID

func (*Form) SetCorsConfig added in v0.1.5

func (f *Form) SetCorsConfig(origins, methods, headers []string)

SetCorsConfig sets the CORS configuration for this form

func (*Form) SetID added in v0.1.5

func (f *Form) SetID(id string)

SetID sets the form's ID

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" gorm:"column:uuid;primaryKey;type:uuid;default:gen_random_uuid()"`
	FormID      string           `json:"form_id" gorm:"not null;index;type:uuid"`
	Data        JSON             `json:"data" gorm:"type:jsonb;not null"`
	SubmittedAt time.Time        `json:"submitted_at" gorm:"not null"`
	Status      SubmissionStatus `json:"status" gorm:"not null;size:20"`
	Metadata    JSON             `json:"metadata" gorm:"type:jsonb"`
	CreatedAt   time.Time        `json:"created_at" gorm:"not null;autoCreateTime"`
	UpdatedAt   time.Time        `json:"updated_at" gorm:"not null;autoUpdateTime"`
}

FormSubmission represents a form submission

func (*FormSubmission) AddMetadata

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

AddMetadata adds metadata to the submission

func (*FormSubmission) GetID added in v0.1.5

func (fs *FormSubmission) GetID() string

GetID returns the submission's ID

func (*FormSubmission) GetMetadata

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

GetMetadata returns the metadata value for a key

func (*FormSubmission) IsCompleted added in v0.1.5

func (fs *FormSubmission) IsCompleted() bool

IsCompleted returns whether the submission is completed

func (*FormSubmission) IsFailed added in v0.1.5

func (fs *FormSubmission) IsFailed() bool

IsFailed returns whether the submission failed

func (*FormSubmission) IsPending added in v0.1.5

func (fs *FormSubmission) IsPending() bool

IsPending returns whether the submission is pending

func (*FormSubmission) IsProcessing added in v0.1.5

func (fs *FormSubmission) IsProcessing() bool

IsProcessing returns whether the submission is being processed

func (*FormSubmission) Sanitize added in v0.1.5

func (fs *FormSubmission) Sanitize(sanitizer sanitization.ServiceInterface)

Sanitize sanitizes the form submission data using the provided sanitizer

func (*FormSubmission) SetID added in v0.1.5

func (fs *FormSubmission) SetID(id string)

SetID sets the submission's ID

func (*FormSubmission) SetStatus added in v0.1.5

func (fs *FormSubmission) SetStatus(status SubmissionStatus)

SetStatus sets the submission status

func (*FormSubmission) UpdateStatus

func (fs *FormSubmission) UpdateStatus(status SubmissionStatus)

UpdateStatus updates the submission status

func (*FormSubmission) Validate

func (fs *FormSubmission) Validate() error

Validate validates the form submission

type JSON added in v0.1.5

type JSON map[string]any

JSON is a custom type for handling JSON data

func (*JSON) MarshalJSON added in v0.1.5

func (j *JSON) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

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) UnmarshalJSON added in v0.1.5

func (j *JSON) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

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