question

package
v0.0.0-...-b8330c8 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidID      = errors.New("invalid question id")
	ErrInvalidContent = errors.New("invalid question content")
	ErrInvalidType    = errors.New("invalid question type")
	ErrInvalidExamID  = errors.New("invalid exam id")
)

Functions

This section is empty.

Types

type Filter

type Filter struct {
	ExamID int32 `json:"exam_id,omitempty"`
}

Filter is a filter for listing questions.

type ListData

type ListData struct {
	// Questions is the list of questions returned from the operation.
	Questions []Question `json:"questions,omitempty"`
	// Total is the total number of questions available in the store.
	TotalSize int32 `json:"total_size,omitempty"`
}

ListData is the data returned by the list operation.

type ListOptions

type ListOptions struct {
	Filter Filter `json:"filter,omitempty"`
	Size   int32  `json:"size,omitempty"`
	Page   int32  `json:"limit,omitempty"`
}

ListOptions is a list options for listing questions with pagination. Nil filter are ignored.

func (*ListOptions) Validate

func (o *ListOptions) Validate() error

type Question

type Question struct {
	ID            int32       `json:"id,omitempty"`
	Type          Type        `json:"type,omitempty"`
	ContentFormat format.Text `json:"content_format,omitempty"`
	Content       string      `json:"content,omitempty"`
	ExamID        int32       `json:"exam_id,omitempty"`
}

Question is a question in an exam.

func (*Question) Validate

func (q *Question) Validate() error

Validate checks if the question is valid.

func (*Question) ValidateNew

func (q *Question) ValidateNew() error

ValidateNew validates a new question.

type Service

type Service interface {
	Save(ctx context.Context, q Question) (Question, error)
	GetByID(ctx context.Context, id int32) (Question, error)
	List(ctx context.Context, opts ListOptions) (ListData, error)
	Update(ctx context.Context, q Question) (Question, error)
	Delete(ctx context.Context, id int32) error
}

func NewService

func NewService(logger *logrus.Entry, questionStore Store) (Service, error)

type Store

type Store interface {
	Save(ctx context.Context, q Question) (Question, error)
	GetByID(ctx context.Context, id int32) (Question, error)
	List(ctx context.Context, offset int32, limit int32, f Filter) ([]Question, error)
	GetTotalSize(ctx context.Context, f Filter) (int32, error)
	Update(ctx context.Context, q Question) (Question, error)
	Delete(ctx context.Context, id int32) error
}

func NewSQLiteStore

func NewSQLiteStore(logger *logrus.Logger, dbPool *sqlitex.Pool) (Store, error)

type Type

type Type int8

Type is the type of the question.

const (
	TypeUnknown Type = iota
	TypeMultipleChoice
	TypeEssay
)

func (Type) String

func (t Type) String() string

func (Type) Valid

func (t Type) Valid() bool

Jump to

Keyboard shortcuts

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