models

package
v0.0.0-...-a5025f8 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Waiting  = SubmissionStatus("waiting")
	Working  = SubmissionStatus("working")
	Finished = SubmissionStatus("finished")
)
View Source
const C = SubmissionLang("c")

Variables

This section is empty.

Functions

func UpdateTest

func UpdateTest(test *Test, request *UpdateTestRequest)

Types

type Api

type Api struct {
	Jwt                string `json:"jwt"`
	AuthCookieLifeTime int    `json:"authCookieLifeTime"`
}

type Command

type Command struct {
	Command string   `json:"command"`
	Args    []string `json:"args"`
}

type Config

type Config struct {
	Database `json:"database"`
	Server   `json:"server"`

	Api  `json:"api"`
	Eval `json:"eval"`

	Languages map[string]Language `json:"languages"`
}

Config is the struct behind the config.json file. It holds basic configurations for the server to run

func NewConfig

func NewConfig(configPath string) (*Config, error)

NewConfig returns a new Config object that will be read from the configPath provided

func (*Config) JwtSecret

func (c *Config) JwtSecret() string

JwtSecret is a utility function that returns config.Api.Jwt Added to ease the manipulation of the config struct.

type CreateProblemRequest

type CreateProblemRequest struct {
	Name             string            `json:"name"`
	Description      string            `json:"description"`
	ShortDescription string            `json:"shortDescription"`
	Visible          bool              `json:"visible"`
	Difficulty       ProblemDifficulty `json:"difficulty"`
	Grade            ProblemGrade      `json:"grade"`
	Credits          string            `json:"credits"`
	Stream           StreamFlag        `json:"stream"`

	TimeLimit   float64 `json:"timeLimit"`
	MemoryLimit int     `json:"memoryLimit"`
	StackLimit  int     `json:"stackLimit"`
	SourceSize  int     `json:"sourceSize"`
}

func (CreateProblemRequest) Validate

func (data CreateProblemRequest) Validate() error

type CreateSubmissionRequest

type CreateSubmissionRequest struct {
	Lang       SubmissionLang `json:"lang"`
	ProblemId  int            `json:"problemId"`
	SourceCode string         `json:"sourceCode"`
}

func (CreateSubmissionRequest) Validate

func (data CreateSubmissionRequest) Validate() error

type CreateTestRequest

type CreateTestRequest struct {
	ProblemId int    `json:"problemId"`
	Score     int    `json:"score"`
	Input     []byte `json:"input"`
	Output    []byte `json:"output"`
}

func (CreateTestRequest) Validate

func (data CreateTestRequest) Validate() error

type Database

type Database struct {
	Host     string `json:"host"`
	Port     string `json:"port"`
	User     string `json:"user"`
	Password string `json:"password"`
	Name     string `json:"name"`
}

type Eval

type Eval struct {
	IsolatePath string `json:"isolatePath"`

	// Concurrency stuff
	MaxSandboxes int `json:"maxSandboxes"`
	MaxCompile   int `json:"maxCompile"`
	MaxExecute   int `json:"maxExecute"`
	MaxCheck     int `json:"maxCheck"`

	CompilePath string `json:"compilePath"`
	OutputPath  string `json:"outputPath"`
	LoggerPath  string `json:"loggerPath"`
}

type ExecuteRequest

type ExecuteRequest struct {
	SourceCode []byte
	Language   *Language
	Problem    *Problem
}

type FullTest

type FullTest struct {
	Test   `json:"test"`
	Input  string `json:"input"`
	Output string `json:"output"`
}

FullTest is an extended Test that has input and output fields.

func NewFullTest

func NewFullTest(test Test, inputUri, outputUri string) *FullTest

type Language

type Language struct {
	Extension  string `json:"extension"`
	IsCompiled bool   `json:"isCompiled"`

	Compile []string `json:"compile"`
	Execute []string `json:"execute"`

	SourceFile string `json:"sourceFile"`
	Executable string `json:"executable"`
}

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

func (LoginRequest) Validate

func (data LoginRequest) Validate() error

type Problem

type Problem struct {
	Id        uint64     `json:"id"`
	CreatedAt *time.Time `json:"createdAt" db:"created_at"`

	Name             string            `json:"name" db:"name"`
	Description      string            `json:"description" db:"description"`
	ShortDescription string            `json:"shortDescription" db:"short_description"`
	AuthorId         uint64            `json:"authorId" db:"author_id"`
	Visible          bool              `json:"visible" db:"visible"`
	Difficulty       ProblemDifficulty `json:"difficulty" db:"difficulty"`
	Grade            ProblemGrade      `json:"grade" db:"grade"`
	Credits          string            `json:"credits" db:"credits"`
	Stream           StreamFlag        `json:"stream" db:"stream"`

	TimeLimit   float64 `json:"timeLimit" db:"time_limit"`
	MemoryLimit int     `json:"memoryLimit" db:"memory_limit"`
	StackLimit  int     `json:"stackLimit" db:"stack_limit"`
	SourceSize  int     `json:"sourceSize" db:"source_size"`
}

func NewProblem

func NewProblem(request CreateProblemRequest) *Problem

func (Problem) IsConsoleProblem

func (p Problem) IsConsoleProblem() bool

type ProblemDifficulty

type ProblemDifficulty string
const (
	Easy    ProblemDifficulty = "easy"
	Medium  ProblemDifficulty = "medium"
	Hard    ProblemDifficulty = "hard"
	Contest ProblemDifficulty = "contest"
)

type ProblemFilter

type ProblemFilter struct {
	AuthorsId    []int
	Difficulties []string
	Credits      []string
	Stream       []string
	Grades       []string
}

func ParseProblemFilter

func ParseProblemFilter(r *http.Request) *ProblemFilter

type ProblemGrade

type ProblemGrade string

ex. clasa a 9, clasa a 10 etc

const (
	NINE   ProblemGrade = "9"
	TEN    ProblemGrade = "10"
	ELEVEN ProblemGrade = "11"
)

type Server

type Server struct {
	Host string `json:"host"`
	Port string `json:"port"`
}

type SignupRequest

type SignupRequest struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

func (SignupRequest) Validate

func (data SignupRequest) Validate() error

type StreamFlag

type StreamFlag string
const (
	CONSOLE StreamFlag = "console"
	FILE    StreamFlag = "file"
)

type Submission

type Submission struct {
	Id        uint64     `json:"id"`
	CreatedAt *time.Time `json:"createdAt" db:"created_at"`

	Score           int              `json:"score"`
	Lang            SubmissionLang   `json:"lang"`
	Status          SubmissionStatus `json:"status"`
	Message         string           `json:"message"`
	HasCompileError *bool            `json:"hasCompileError" db:"has_compile_error"`

	ProblemId  int    `json:"problemId" db:"problem_id"`
	UserId     int    `json:"userId" db:"user_id"`
	SourceCode string `json:"sourceCode" db:"source_code"`
}

func NewSubmission

func NewSubmission(request CreateSubmissionRequest, userId int) *Submission

type SubmissionFilter

type SubmissionFilter struct {
	UserId       int
	ProblemId    int
	Score        int
	Langs        []SubmissionLang
	Statuses     []SubmissionStatus
	CompileError *bool // nil == skip(does not matter), false no compile error, true compile errors
}

func ParseSubmissionFilter

func ParseSubmissionFilter(r *http.Request) *SubmissionFilter

type SubmissionLang

type SubmissionLang string

type SubmissionStatus

type SubmissionStatus string

type SubmissionTest

type SubmissionTest struct {
	Id          uint64     `json:"id"`
	EvaluatedAt *time.Time `json:"evaluatedAt" db:"evaluated_at"`

	Score  int     `json:"score"`
	Time   float64 `json:"time"`
	Memory int     `json:"memory"` // in kb

	Message  string `json:"message"`
	ExitCode int    `json:"exitCode" db:"exit_code"`

	SubmissionId uint64 `json:"submissionId" db:"submission_id"`
	TestId       uint64 `json:"testId" db:"test_id"`
}

func NewSubmissionTest

func NewSubmissionTest(submissionId, testId uint64) *SubmissionTest

type Test

type Test struct {
	Id        uint64     `json:"id" db:"id"`
	CreatedAt *time.Time `json:"createdAt" db:"created_at"`

	ProblemId int `json:"problemId" db:"problem_id"`
	Score     int `json:"score" db:"score"`
}

func NewTest

func NewTest(request CreateTestRequest) *Test

type UpdateProblemRequest

type UpdateProblemRequest struct {
	Name             string            `json:"name"`
	Description      string            `json:"description"`
	ShortDescription string            `json:"shortDescription"`
	AuthorId         uint64            `json:"authorId"`
	Visible          bool              `json:"visible"`
	Difficulty       ProblemDifficulty `json:"difficulty"`
	Grade            ProblemGrade      `json:"grade"`
	Credits          string            `json:"credits"`
	Stream           StreamFlag        `json:"stream"` // TODO the validation is broken

	TimeLimit   float64 `json:"timeLimit"`
	MemoryLimit int     `json:"memoryLimit"`
	StackLimit  int     `json:"stackLimit"`
	SourceSize  int     `json:"sourceSize"`
}

type UpdateSubmissionRequest

type UpdateSubmissionRequest struct {
	Score           int
	Status          SubmissionStatus
	Message         string
	HasCompileError *bool
}

func NewUpdateSubmissionRequest

func NewUpdateSubmissionRequest(score int, status SubmissionStatus, message string, compileError *bool) *UpdateSubmissionRequest

type UpdateSubmissionTestRequest

type UpdateSubmissionTestRequest struct {
	Score  int     `json:"score"`
	Time   float64 `json:"time"`
	Memory int     `json:"memory"`

	Message  string `json:"message"`
	ExitCode int    `json:"exitCode" db:"exit_code"` // -1 == do not update
}

type UpdateTestRequest

type UpdateTestRequest struct {
	Score  int    `json:"score"`
	Input  []byte `json:"input"`
	Output []byte `json:"output"`
}

TODO add input and output validation

func (UpdateTestRequest) Validate

func (data UpdateTestRequest) Validate() error

type User

type User struct {
	Id        uint64     `json:"id"`
	CreatedAt *time.Time `json:"createdAt" db:"created_at"`

	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"-"`
	Bio      string `json:"bio"`
	Visible  bool   `json:"visible"`

	IsAdmin    bool `json:"isAdmin" db:"is_admin"`
	IsProposer bool `json:"isProposer" db:"is_proposer"`
	IsBanned   bool `json:"isBanned" db:"is_banned"`

	VerifiedEmail           bool       `json:"verifiedEmail" db:"verified_email"`
	EmailVerificationSentAt *time.Time `json:"emailVerificationSentAt" db:"email_verification_sent_at"`
}

User represents a user entity

func NewUser

func NewUser(username, email, password string) *User

NewUser creates a new user with the given username, email and password

Jump to

Keyboard shortcuts

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