form

package
v0.0.0-...-edc9f9a Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// These variables are used to make the code testable
	UUIDNew = uuid.New
	TimeNow = time.Now
)
View Source
var (
	ErrNotFound = errors.New("not found")
	ErrBadArgs  = errors.New("bad arguments")
)

Functions

This section is empty.

Types

type CheckboxQuestion

type CheckboxQuestion struct {
	QuestionBase
	Options []string
}

func (CheckboxQuestion) Validate

func (q CheckboxQuestion) Validate() error

type CreateFormParams

type CreateFormParams struct {
	Title       string
	Description string
	Questions   []CreateQuestionParams
}

type CreateQuestionParams

type CreateQuestionParams struct {
	Type  QuestionType
	Title string
	// Options is only required for radio and checkbox questions
	Options []string
}

type Form

type Form struct {
	FormBase
	Questions []Question
}

type FormBase

type FormBase struct {
	BaseId    uuid.UUID
	VersionId uuid.UUID
	Version   uint32

	Title       string
	Description string
	CreatedAt   time.Time
}

type ListFormsParams

type ListFormsParams struct {
}

type Question

type Question interface {
	Question() QuestionBase
	Validate() error
}

type QuestionBase

type QuestionBase struct {
	Id    uuid.UUID
	Title string
}

func (QuestionBase) Question

func (q QuestionBase) Question() QuestionBase

func (QuestionBase) Validate

func (q QuestionBase) Validate() error

type QuestionType

type QuestionType int
const (
	QuestionTypeText     QuestionType = 0
	QuestionTypeRadio    QuestionType = 1
	QuestionTypeCheckbox QuestionType = 2
)

type RadioQuestion

type RadioQuestion struct {
	QuestionBase
	Options []string
}

func (RadioQuestion) Validate

func (q RadioQuestion) Validate() error

type Repo

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

func NewPgRepo

func NewPgRepo(dbpool *pgxpool.Pool) *Repo

func (*Repo) CreateForm

func (r *Repo) CreateForm(ctx context.Context, form Form) error

func (*Repo) GetLatestVersionOfForm

func (r *Repo) GetLatestVersionOfForm(ctx context.Context, formID uuid.UUID) (Form, error)

func (*Repo) GetQuestions

func (r *Repo) GetQuestions(ctx context.Context, formVersionID string) ([]Question, error)

func (*Repo) ListForms

func (r *Repo) ListForms(ctx context.Context, params ListFormsParams) ([]Form, error)

type Service

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

func NewService

func NewService(repo *Repo) *Service

func (*Service) CreateNewForm

func (s *Service) CreateNewForm(ctx context.Context, params CreateFormParams) (Form, error)

func (*Service) GetForm

func (s *Service) GetForm(ctx context.Context, id uuid.UUID) (Form, error)

func (*Service) ListForms

func (s *Service) ListForms(ctx context.Context, params ListFormsParams) ([]Form, error)

func (*Service) UpdateForm

func (s *Service) UpdateForm(ctx context.Context, params UpdateFormParams) (Form, error)

type TextQuestion

type TextQuestion struct {
	QuestionBase
}

func (TextQuestion) Validate

func (q TextQuestion) Validate() error

type UpdateFormParams

type UpdateFormParams struct {
	Id uuid.UUID
	CreateFormParams
}

Jump to

Keyboard shortcuts

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