form

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFormSchemaNotFound is returned when a form schema cannot be found
	ErrFormSchemaNotFound = errors.New("form schema not found")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	SubmitForm(ctx context.Context, form Form) error
	GetForm(ctx context.Context, formID string) (*Form, error)
	ListForms(ctx context.Context) ([]Form, error)
	DeleteForm(ctx context.Context, formID string) error
	UpdateForm(ctx context.Context, formID string, form Form) error
	SubmitResponse(ctx context.Context, formID string, response Response) error
	GetResponse(ctx context.Context, responseID string) (*Response, error)
	ListResponses(ctx context.Context, formID string) ([]Response, error)
	DeleteResponse(ctx context.Context, responseID string) error
}

Client represents a form client interface

type Field

type Field struct {
	Name string
	Type string
}

Field represents a form field

type Form

type Form struct {
	ID          string    `json:"id"`
	UserID      uint      `json:"user_id"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Schema      JSON      `json:"schema"`
	Active      bool      `json:"active"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Form represents a form in the system

type InMemoryFormSchemaRepo

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

InMemoryFormSchemaRepo is a simple in-memory implementation for demo/testing Not safe for concurrent use in production!

func NewInMemoryFormSchemaRepo

func NewInMemoryFormSchemaRepo() *InMemoryFormSchemaRepo

NewInMemoryFormSchemaRepo creates a new in-memory form schema repository

func (*InMemoryFormSchemaRepo) Create

Create stores a new form schema

func (*InMemoryFormSchemaRepo) Delete

func (r *InMemoryFormSchemaRepo) Delete(id uint) error

Delete removes a form schema by ID

func (*InMemoryFormSchemaRepo) Get

Get retrieves a form schema by ID

func (*InMemoryFormSchemaRepo) List

func (r *InMemoryFormSchemaRepo) List() ([]*model.FormSchema, error)

List returns all form schemas

func (*InMemoryFormSchemaRepo) Update

func (r *InMemoryFormSchemaRepo) Update(id uint, schema *model.FormSchema) (*model.FormSchema, error)

Update modifies an existing form schema

type JSON

type JSON map[string]any

JSON represents a JSON object

type Options

type Options struct {
}

Options represents configuration options for a form

type Response

type Response struct {
	ID          string
	FormID      string
	Values      map[string]any
	SubmittedAt time.Time
}

Response represents a form submission response

type SchemaRepository

type SchemaRepository interface {
	List() ([]*model.FormSchema, error)
	Create(schema *model.FormSchema) (*model.FormSchema, error)
	Get(id uint) (*model.FormSchema, error)
	Update(id uint, schema *model.FormSchema) (*model.FormSchema, error)
	Delete(id uint) error
}

SchemaRepository defines the interface for form schema storage

type Service

type Service interface {
	CreateForm(userID uint, title, description string, schema JSON) (*Form, error)
	GetForm(id string) (*Form, error)
	GetUserForms(userID uint) ([]*Form, error)
	UpdateForm(form *Form) error
	DeleteForm(id string) error
	GetFormSubmissions(formID string) ([]*model.FormSubmission, error)
}

Service defines the interface for form operations

func NewService

func NewService(store Store) Service

NewService creates a new form service instance

type Store

type Store interface {
	Create(f *Form) error
	GetByID(id string) (*Form, error)
	GetByUserID(userID uint) ([]*Form, error)
	Delete(id string) error
	Update(f *Form) error
	GetFormSubmissions(formID string) ([]*model.FormSubmission, error)
}

Store defines the interface for form storage operations

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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