answer

package
v0.0.0-...-c99e1c3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidRecord = errors.New("invalid answer record")

Functions

func Limit

func Limit(n int) qm.QueryMod

func Offset

func Offset(n int) qm.QueryMod

func OrderByCreatedAtDesc

func OrderByCreatedAtDesc() qm.QueryMod

func WhereIDEq

func WhereIDEq(id uuid.UUID) qm.QueryMod

func WhereUserIDEq

func WhereUserIDEq(userID uuid.UUID) qm.QueryMod

Types

type Answer

type Answer struct {
	ID        uuid.UUID
	UserID    uuid.UUID
	ChoiceID  uuid.UUID
	CreatedAt time.Time
}

Answer represents the choice selected by a user for a question.

func New

func New(userID, choiceID uuid.UUID) *Answer

New creates a new Answer with a random ID, and with the specified user ID and choice ID.

func (Answer) Validate

func (a Answer) Validate() error

Validate checks if the answer is valid.

type LogItem

type LogItem struct {
	ID       uuid.UUID
	Question question.Question
	ChoiceID uuid.UUID
}

LogItem represents a previous attempt at answering a question.

func (LogItem) IsSuccessful

func (l LogItem) IsSuccessful() (bool, error)

IsSuccessful returns whether the answer was correct or not.

type LogRequest

type LogRequest struct {
	UserID     uuid.UUID
	Pagination pagination.Pagination
}

LogRequest has the parameters for retrieving a user's history of answers.

type Repository

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

func NewRepository

func NewRepository(db *sql.DB) *Repository

func (*Repository) GetMany

func (r *Repository) GetMany(ctx context.Context, qms ...qm.QueryMod) ([]Answer, error)

func (*Repository) GetOne

func (r *Repository) GetOne(ctx context.Context, qms ...qm.QueryMod) (*Answer, error)

func (*Repository) Insert

func (r *Repository) Insert(ctx context.Context, a Answer) error

type Service

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

Service represents the service that manages answers.

func NewService

func NewService(repo *Repository, questionService *question.Service) *Service

NewService creates a new instance of answer.Service.

func (Service) LogFor

func (s Service) LogFor(ctx context.Context, req LogRequest) ([]LogItem, error)

LogFor returns the paginated history of answers for a user.

func (Service) Submit

func (s Service) Submit(
	ctx context.Context,
	userID, choiceID uuid.UUID,
) (*SubmissionResponse, error)

Submit registers the choice made by a user for a specific question, and returns the correct choice for it, plus some more info for the user to know how they did.

type SubmissionResponse

type SubmissionResponse struct {
	ID              uuid.UUID
	CorrectChoiceID uuid.UUID
	MoreInfo        string
}

Jump to

Keyboard shortcuts

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