answer

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 answer id")
	ErrInvalidType         = errors.New("invalid answer type")
	ErrInvalidEssayFormat  = errors.New("invalid essay content format")
	ErrInvalidEssayContent = errors.New("invalid essay content")
	ErrInvalidChoiceID     = errors.New("invalid choice id")
)

Functions

This section is empty.

Types

type Answer

type Answer struct {
	ID            int32 `json:"id,omitempty"`
	Correct       bool  `json:"correct"`
	ParticipantID int32 `json:"participant_id,omitempty"`
	QuestionID    int32 `json:"question_id,omitempty"`
	// Types that are valid to be assigned to Content:
	//	ContentChoiceID
	//	ContentEssay
	Content isAnswerContent `json:"content,omitempty"`
}

func (*Answer) Validate

func (a *Answer) Validate() error

func (*Answer) ValidateNew

func (a *Answer) ValidateNew() error

type ContentChoiceID

type ContentChoiceID int32

func (ContentChoiceID) Validate

func (c ContentChoiceID) Validate() error

type ContentEssay

type ContentEssay struct {
	ContentFormat format.Text `json:"content_format,omitempty"`
	Content       string      `json:"content,omitempty"`
}

func (ContentEssay) Validate

func (c ContentEssay) Validate() error

type Filter

type Filter struct {
	ParticipantID int32 `json:"participant_id,omitempty"`
	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.
	Answers []Answer `json:"answers,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.

func (*ListOptions) Validate

func (o *ListOptions) Validate() error

type Service

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

func NewService

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

type Store

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

func NewSQLiteStore

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

Jump to

Keyboard shortcuts

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