forms

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	DefaultFormType string                 `json:"defaultFormType"`
	MaxFieldCount   int                    `json:"maxFieldCount"`
	MaxFileSize     int64                  `json:"maxFileSize"`
	AllowedTypes    []string               `json:"allowedTypes"`
	ValidationRules map[string]interface{} `json:"validationRules"`
}

Config represents the forms configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default forms configuration

type CreateFormRequest

type CreateFormRequest struct {
	AppID       xid.ID                 `json:"appId"`
	Type        string                 `json:"type"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Schema      map[string]interface{} `json:"schema"`
}

CreateFormRequest represents a request to create a new form

type Form

type Form struct {
	ID          xid.ID                 `json:"id"`
	AppID       xid.ID                 `json:"appId"`
	Type        string                 `json:"type"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Schema      map[string]interface{} `json:"schema"`
	IsActive    bool                   `json:"isActive"`
	Version     int                    `json:"version"`
	CreatedAt   time.Time              `json:"createdAt"`
	UpdatedAt   time.Time              `json:"updatedAt"`
}

Form represents a form configuration

type FormField

type FormField struct {
	ID          string                 `json:"id"`
	Type        string                 `json:"type"`
	Label       string                 `json:"label"`
	Placeholder string                 `json:"placeholder"`
	Required    bool                   `json:"required"`
	Validation  map[string]interface{} `json:"validation"`
	Options     []string               `json:"options,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

FormField represents a form field configuration

type FormSubmission

type FormSubmission struct {
	ID           xid.ID                 `json:"id"`
	FormSchemaID xid.ID                 `json:"formSchemaId"`
	UserID       *xid.ID                `json:"userId"`
	SessionID    *xid.ID                `json:"sessionId"`
	Data         map[string]interface{} `json:"data"`
	IPAddress    string                 `json:"ipAddress"`
	UserAgent    string                 `json:"userAgent"`
	Status       string                 `json:"status"`
	CreatedAt    time.Time              `json:"createdAt"`
	UpdatedAt    time.Time              `json:"updatedAt"`
}

FormSubmission represents a form submission

type ListFormsRequest

type ListFormsRequest struct {
	OrganizationID xid.ID `json:"organizationId"`
	Type           string `json:"type,omitempty"`
	Page           int    `json:"page"`
	PageSize       int    `json:"pageSize"`
}

ListFormsRequest represents a request to list forms

type ListFormsResponse

type ListFormsResponse struct {
	Forms      []*Form `json:"forms"`
	Total      int     `json:"total"`
	Page       int     `json:"page"`
	PageSize   int     `json:"pageSize"`
	TotalPages int     `json:"totalPages"`
}

ListFormsResponse represents a response with forms list

type Repository

type Repository interface {
	// Form management
	Create(ctx context.Context, form *schema.FormSchema) error
	GetByID(ctx context.Context, id xid.ID) (*schema.FormSchema, error)
	GetByOrganization(ctx context.Context, orgID xid.ID, formType string) (*schema.FormSchema, error)
	List(ctx context.Context, orgID xid.ID, formType string, page, pageSize int) ([]*schema.FormSchema, int, error)
	Update(ctx context.Context, form *schema.FormSchema) error
	Delete(ctx context.Context, id xid.ID) error

	// Form submissions
	CreateSubmission(ctx context.Context, submission *schema.FormSubmission) error
	GetSubmissionByID(ctx context.Context, id xid.ID) (*schema.FormSubmission, error)
	ListSubmissions(ctx context.Context, formSchemaID xid.ID, page, pageSize int) ([]*schema.FormSubmission, int, error)
	GetSubmissionsByUser(ctx context.Context, userID xid.ID, page, pageSize int) ([]*schema.FormSubmission, int, error)
}

Repository defines the interface for form data access

type SaveFormSchemaRequest

type SaveFormSchemaRequest struct {
	OrganizationID xid.ID                 `json:"organization_id"`
	Schema         map[string]interface{} `json:"schema"`
}

SaveFormSchemaRequest represents a request to save a form schema

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service handles form business logic

func NewService

func NewService(forgeConfig interface{}, repo Repository) (*Service, error)

NewService creates a new forms service

func (*Service) CreateForm

func (s *Service) CreateForm(ctx context.Context, req *CreateFormRequest) (*Form, error)

CreateForm creates a new form configuration

func (*Service) DeleteForm

func (s *Service) DeleteForm(ctx context.Context, id xid.ID) error

DeleteForm deletes a form

func (*Service) GetDefaultSignupForm

func (s *Service) GetDefaultSignupForm() map[string]interface{}

GetDefaultSignupForm returns the default signup form configuration

func (*Service) GetForm

func (s *Service) GetForm(ctx context.Context, id xid.ID) (*Form, error)

GetForm retrieves a form by ID

func (*Service) GetFormByOrganization

func (s *Service) GetFormByOrganization(ctx context.Context, orgID xid.ID, formType string) (*Form, error)

GetFormByOrganization retrieves a form by organization and type

func (*Service) GetSubmission

func (s *Service) GetSubmission(ctx context.Context, id xid.ID) (*FormSubmission, error)

GetSubmission retrieves a form submission by ID

func (*Service) ListForms

func (s *Service) ListForms(ctx context.Context, req *ListFormsRequest) (*ListFormsResponse, error)

ListForms lists forms for an organization

func (*Service) SubmitForm

func (s *Service) SubmitForm(ctx context.Context, req *SubmitFormRequest) (*FormSubmission, error)

SubmitForm submits form data

func (*Service) UpdateForm

func (s *Service) UpdateForm(ctx context.Context, req *UpdateFormRequest) (*Form, error)

UpdateForm updates an existing form

type SignupFormService

type SignupFormService struct {
	// contains filtered or unexported fields
}

SignupFormService handles signup form management with Smartform integration

func NewSignupFormService

func NewSignupFormService(service *Service) *SignupFormService

NewSignupFormService creates a new signup form service

func (*SignupFormService) DeleteCustomForm

func (s *SignupFormService) DeleteCustomForm(ctx context.Context, orgID xid.ID) error

DeleteCustomForm removes a custom signup form for an organization

func (*SignupFormService) GetCustomForm

func (s *SignupFormService) GetCustomForm(ctx context.Context, orgID xid.ID) (*Form, error)

GetCustomForm retrieves a custom signup form for an organization

func (*SignupFormService) GetSignupForm

func (s *SignupFormService) GetSignupForm(ctx context.Context, orgID xid.ID) (*Form, error)

GetSignupForm retrieves the signup form for an organization Returns custom form if exists, otherwise returns default form

func (*SignupFormService) SaveFormSchema

func (s *SignupFormService) SaveFormSchema(ctx context.Context, req *SaveFormSchemaRequest) (*Form, error)

SaveFormSchema saves a custom signup form schema for an organization

func (*SignupFormService) SubmitSignupForm

func (s *SignupFormService) SubmitSignupForm(ctx context.Context, req *SubmitSignupFormRequest) (*FormSubmission, error)

SubmitSignupForm processes a signup form submission

type SubmitFormRequest

type SubmitFormRequest struct {
	FormSchemaID xid.ID                 `json:"formSchemaId"`
	UserID       *xid.ID                `json:"userId"`
	SessionID    *xid.ID                `json:"sessionId"`
	Data         map[string]interface{} `json:"data"`
	IPAddress    string                 `json:"ipAddress"`
	UserAgent    string                 `json:"userAgent"`
}

SubmitFormRequest represents a request to submit a form

type SubmitSignupFormRequest

type SubmitSignupFormRequest struct {
	OrganizationID xid.ID                 `json:"organization_id"`
	Data           map[string]interface{} `json:"data"`
	IPAddress      string                 `json:"ip_address,omitempty"`
	UserAgent      string                 `json:"user_agent,omitempty"`
}

SubmitSignupFormRequest represents a signup form submission request

type UpdateFormRequest

type UpdateFormRequest struct {
	ID          xid.ID                 `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Schema      map[string]interface{} `json:"schema"`
	IsActive    bool                   `json:"isActive"`
}

UpdateFormRequest represents a request to update a form

Jump to

Keyboard shortcuts

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