payloads

package
v2.23.7 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package payloads defines data structures to be used as tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertIntoMap

func ConvertIntoMap(source interface{}) map[string]interface{}

ConvertIntoMap converts a struct into a map Fields without a `json` tag or having '-' as a json field name are skipped.

func ParseMap

func ParseMap(raw map[string]interface{}, target interface{}) error

ParseMap converts a map into a structure and validates fields.

Types

type AnswerToken

type AnswerToken struct {
	// Nullable fields are of pointer types
	Date            string  `json:"date" validate:"dmy-date"` // dd-mm-yyyy
	UserID          string  `json:"idUser"`
	ItemID          *string `json:"idItem"` // always is nil?
	AttemptID       string  `json:"idAttempt"`
	ItemURL         string  `json:"itemUrl"`
	LocalItemID     string  `json:"idItemLocal"`
	PlatformName    string  `json:"platformName" validate:"min=1,max=200"` // 1 <= length <= 200
	RandomSeed      string  `json:"randomSeed"`
	HintsRequested  *string `json:"sHintsRequested"`
	HintsGivenCount string  `json:"nbHintsGiven"`
	Answer          string  `json:"sAnswer"`
	UserAnswerID    string  `json:"idUserAnswer"`

	Converted  AnswerTokenConverted
	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
}

AnswerToken represents data inside an answer token. idAttempt is required.

func (*AnswerToken) Bind

func (tt *AnswerToken) Bind() error

Bind validates a score token and converts some needed field values (called by ParseMap).

type AnswerTokenConverted

type AnswerTokenConverted struct {
	UserID        int64
	UserAnswerID  int64
	LocalItemID   int64
	ParticipantID int64
	AttemptID     int64
}

AnswerTokenConverted contains converted field values of AnswerToken payload.

type Binder

type Binder interface {
	Bind() error
}

Binder is an interface for managing payloads.

type HintToken

type HintToken struct {
	Date        string            `json:"date" validate:"dmy-date"` // dd-mm-yyyy
	UserID      string            `json:"idUser,omitempty"`
	ItemID      *string           `json:"idItem,omitempty"`
	LocalItemID string            `json:"idItemLocal"`
	ItemURL     string            `json:"itemUrl"`
	AttemptID   string            `json:"idAttempt"`
	AskedHint   formdata.Anything `json:"askedHint"`

	Converted HintTokenConverted

	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
}

HintToken represents data inside a hint token.

func (*HintToken) Bind

func (tt *HintToken) Bind() error

Bind validates a hint token and converts some needed field values (called by ParseMap).

func (*HintToken) UnmarshalJSON

func (tt *HintToken) UnmarshalJSON(raw []byte) error

UnmarshalJSON unmarshals the hint token payload from JSON.

type HintTokenConverted

type HintTokenConverted struct {
	UserID int64
}

HintTokenConverted contains converted field values of HintToken payload.

type ScoreToken

type ScoreToken struct {
	// Nullable fields are of pointer types
	Date         string  `json:"date" validate:"dmy-date"` // dd-mm-yyyy
	UserID       string  `json:"idUser"`
	ItemID       *string `json:"idItem,omitempty"`
	LocalItemID  string  `json:"idItemLocal"`
	AttemptID    string  `json:"idAttempt"`
	ItemURL      string  `json:"itemUrl"`
	Score        string  `json:"score"`
	UserAnswerID string  `json:"idUserAnswer"`
	Answer       *string `json:"sAnswer"`

	Converted  ScoreTokenConverted
	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
}

ScoreToken represents data inside a score token.

func (*ScoreToken) Bind

func (tt *ScoreToken) Bind() error

Bind validates a score token and converts some needed field values (called by ParseMap).

type ScoreTokenConverted

type ScoreTokenConverted struct {
	UserID        int64
	UserAnswerID  int64
	Score         float64
	LocalItemID   int64
	ParticipantID int64
	AttemptID     int64
}

ScoreTokenConverted contains converted field values of ScoreToken payload.

type TaskToken

type TaskToken struct {
	// Nullable fields are of pointer types
	Date               string  `json:"date" validate:"set,dmy-date"` // dd-mm-yyyy
	UserID             string  `json:"idUser"`
	ItemID             *string `json:"idItem,omitempty"` // always is nil?
	AttemptID          string  `json:"idAttempt"`
	ItemURL            string  `json:"itemUrl"`
	LocalItemID        string  `json:"idItemLocal"`
	PlatformName       string  `json:"platformName" validate:"min=1,max=200"` // 1 <= length <= 200
	RandomSeed         string  `json:"randomSeed"`
	TaskID             *string `json:"idTask,omitempty"` // always is nil?
	HintsAllowed       *bool   `json:"bHintsAllowed,omitempty"`
	HintPossible       *bool   `json:"bHintPossible,omitempty"`
	HintsRequested     *string `json:"sHintsRequested,omitempty"`
	HintsGivenCount    *string `json:"nbHintsGiven,omitempty"`
	AccessSolutions    *bool   `json:"bAccessSolutions,omitempty"`
	ReadAnswers        *bool   `json:"bReadAnswers,omitempty"`
	Login              *string `json:"sLogin,omitempty"`
	SubmissionPossible *bool   `json:"bSubmissionPossible,omitempty"`
	SupportedLangProg  *string `json:"sSupportedLangProg,omitempty"`
	IsAdmin            *bool   `json:"bIsAdmin,omitempty"`

	Converted TaskTokenConverted

	PublicKey  *rsa.PublicKey
	PrivateKey *rsa.PrivateKey
}

TaskToken represents data inside a task token.

func (*TaskToken) Bind

func (tt *TaskToken) Bind() error

Bind validates a task token and converts some needed field values.

type TaskTokenConverted

type TaskTokenConverted struct {
	UserID        int64
	LocalItemID   int64
	ParticipantID int64
	AttemptID     int64
}

TaskTokenConverted contains converted field values of TaskToken payload.

type ThreadToken

type ThreadToken struct {
	// Format dd-mm-yyyy
	// required:true
	Date string `json:"date" validate:"dmy-date"`
	// required:true
	ItemID string `json:"item_id"`
	// required:true
	ParticipantID string `json:"participant_id"`
	// Current user.
	// required:true
	UserID string `json:"user_id"`
	// Whether the thread is from the current user.
	// required:true
	IsMine bool `json:"is_mine"`
	// Whether the current user can post new content.
	// required:true
	CanWatch bool `json:"can_watch"`
	// Whether the current user can post new content on the thread
	// required:true
	CanWrite bool `json:"can_write"`
	// Expiry date in the number of seconds since 01/01/1970 UTC.
	// required:true
	Exp string `json:"exp"`

	// swagger:ignore
	PublicKey *rsa.PublicKey
	// swagger:ignore
	PrivateKey *rsa.PrivateKey
}

ThreadToken represents data inside a thread token. swagger:model ThreadToken

Jump to

Keyboard shortcuts

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