trainer

package
v0.0.0-...-55b4455 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Choice

type Choice struct {
	ID         int
	Option     string
	Text       string
	IsAnswer   bool
	IsSelected bool
}

type ChoiceEntity

type ChoiceEntity struct {
	ID         int
	QuestionId int
	Option     string
	Text       string
	IsAnswer   bool
}

type Controller

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

func NewController

func NewController(service Service, html fs.FS) *Controller

func (*Controller) Health

func (c *Controller) Health(w http.ResponseWriter, r *http.Request)

func (*Controller) Home

func (c *Controller) Home(w http.ResponseWriter, r *http.Request)

func (*Controller) NewQuestion

func (c *Controller) NewQuestion(w http.ResponseWriter, r *http.Request)

func (*Controller) QuestionList

func (c *Controller) QuestionList(w http.ResponseWriter, r *http.Request)

func (*Controller) RandomQuestion

func (c *Controller) RandomQuestion(w http.ResponseWriter, _ *http.Request)

func (*Controller) Result

func (c *Controller) Result(w http.ResponseWriter, r *http.Request)

type LoadMoreParam

type LoadMoreParam struct {
	Search             string
	LastRuleSortOrder  int
	LastQuestionNumber int
	LastIndex          int
	Limit              int
}

type Question

type Question struct {
	ID                 int
	Text               string
	Rule               Rule
	QuestionNumber     int
	RuleQuestionNumber string
	Choices            []Choice
	References         []Reference
}

type QuestionData

type QuestionData struct {
	Index              int
	RuleID             string
	RuleName           string
	RuleQuestionNumber string
	Text               string
}

type QuestionEntity

type QuestionEntity struct {
	ID             int
	Text           string
	RuleID         string
	QuestionNumber int
}

type QuestionListPageData

type QuestionListPageData struct {
	Questions     []QuestionData
	LoadMoreParam LoadMoreParam
}

type QuestionRepository

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

func NewRepository

func NewRepository(db *pgxpool.Pool) *QuestionRepository

func (*QuestionRepository) FindChoicesByQuestionIds

func (r *QuestionRepository) FindChoicesByQuestionIds(ctx context.Context, questionIds ...int) (map[int][]Choice, error)

FindChoicesByQuestionIds finds choices by question ids and returns a map of question id to choices

func (*QuestionRepository) FindRuleByID

func (r *QuestionRepository) FindRuleByID(ctx context.Context, ruleID string) (*Rule, error)

func (*QuestionRepository) FindRuleByIDs

func (r *QuestionRepository) FindRuleByIDs(ctx context.Context, ruleIDs ...string) (map[string]Rule, error)

FindRuleByIDs finds rules by rule ids and returns a map of rule id to rule

func (*QuestionRepository) GetAllDistinctRuleIDs

func (r *QuestionRepository) GetAllDistinctRuleIDs(ctx context.Context) ([]string, error)

func (*QuestionRepository) GetChoicesByQuestionID

func (r *QuestionRepository) GetChoicesByQuestionID(ctx context.Context, questionID int) ([]Choice, error)

func (*QuestionRepository) GetRandomQuestion

func (r *QuestionRepository) GetRandomQuestion(ctx context.Context, rules []string) (*Question, error)

func (*QuestionRepository) ListQuestions

func (r *QuestionRepository) ListQuestions(ctx context.Context, ruleIDs []string, search string, lastRuleSortOrder int, lastQuestionNumber int, limit int) ([]Question, error)

ListQuestions returns a list of questions supports pagination using the rule sort order and question number of the last question to offset

type QuestionService

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

func NewService

func NewService(repository Repository) *QuestionService

func (*QuestionService) GetChoicesByQuestionID

func (s *QuestionService) GetChoicesByQuestionID(ctx context.Context, questionID int) ([]Choice, error)

func (*QuestionService) GetRandomQuestion

func (s *QuestionService) GetRandomQuestion(ctx context.Context, rules []string) (*Question, error)

func (*QuestionService) ListQuestions

func (s *QuestionService) ListQuestions(ctx context.Context, rules []string, search string, lastRuleSortOrder int, lastQuestionNumber int, limit int) ([]Question, error)

type Reference

type Reference struct {
	ID   int
	Text string
}

type ReferenceEntity

type ReferenceEntity struct {
	ID         int
	QuestionId int
	Text       string
}

type Repository

type Repository interface {
	GetRandomQuestion(ctx context.Context, rules []string) (*Question, error)
	GetChoicesByQuestionID(ctx context.Context, questionID int) ([]Choice, error)
	ListQuestions(ctx context.Context, rules []string, search string, lastRuleSortOrder int, lastQuestionNumber int, limit int) ([]Question, error)
}

type Rule

type Rule struct {
	ID        string
	Name      string
	SortOrder int
}

type RuleEntity

type RuleEntity struct {
	ID        string
	Name      string
	SortOrder int
}

type Service

type Service interface {
	GetRandomQuestion(ctx context.Context, rules []string) (*Question, error)
	GetChoicesByQuestionID(ctx context.Context, questionID int) ([]Choice, error)
	ListQuestions(ctx context.Context, rules []string, search string, lastRuleSortOrder int, lastQuestionNumber int, limit int) ([]Question, error)
}

Jump to

Keyboard shortcuts

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