entities

package
v0.0.0-...-bde7e6f Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SandboxMemoryMB uint = 1024 * 1024
	SandboxMemoryGB uint = 1024 * SandboxMemoryMB
)
View Source
const (
	SubmissionStatusPending  = "PENDING"
	SubmissionStatusCorrect  = "CORRECT"
	SubmissionStatusWrong    = "WRONG"
	SubmissionStatusNotSolve = "NOTSOLVE"
)
View Source
const (
	UserRoleAdmin = "ADMIN"
	UserRoleStaff = "STAFF"
	UserRoleUser  = "USER"
)

Variables

View Source
var CCodeExample = `` /* 136-byte string literal not displayed */
View Source
var CInstructionBook = SandboxInstruction{
	Language:       "c",
	DockerImage:    "docker.io/library/gcc:12.3.0",
	CompileCmd:     "cp /sandbox/code /sandbox/main.c && gcc -o /sandbox/main /sandbox/main.c",
	RunCmd:         "/sandbox/main < /stdin/stdin",
	CompileTimeout: 1000 * 60,
}
View Source
var GoCodeExample = `` /* 345-byte string literal not displayed */
View Source
var GoInstructionBook = SandboxInstruction{
	Language:       "go",
	DockerImage:    "docker.io/library/golang:1.21",
	CompileCmd:     "cd /sandbox && cp /sandbox/code /sandbox/main.go && go mod init sandbox && go build -o /sandbox/main",
	RunCmd:         "/sandbox/main < /stdin/stdin",
	CompileTimeout: 1000 * 60,
}
View Source
var LanguageInstructionMap = map[string]SandboxInstruction{
	"python": PythonInstructionBook,
	"go":     GoInstructionBook,
	"c":      CInstructionBook,
}
View Source
var PythonCodeExample = `
x = int(input())
y = int(input())
print(x + y)
`
View Source
var PythonCodeOOMTestCode = `
data = []

while True:
    data.append(' ' * 10**6)
`
View Source
var PythonCodeTimeoutTestCode = `
import time
time.sleep(2)
`
View Source
var PythonInstructionBook = SandboxInstruction{
	Language:       "python",
	DockerImage:    "docker.io/library/python:3.10",
	CompileCmd:     "cp /sandbox/code /sandbox/code.py",
	RunCmd:         "python3 /sandbox/code.py < /stdin/stdin",
	CompileTimeout: 1000,
}

Functions

This section is empty.

Types

type Challenge

type Challenge struct {
	ID          uint                 `json:"challenge_id" gorm:"primaryKey"`
	Name        string               `json:"name"`
	Description string               `json:"description"`
	UserID      uint                 `json:"user_id"`
	User        *User                `json:"user" gorm:"foreignKey:UserID"`
	Testcases   []*ChallengeTestcase `json:"testcases" gorm:"foreignKey:ChallengeID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
	Submission  []*Submission        `json:"submission" gorm:"foreignKey:ChallengeID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE"`
}

type ChallengeCreateWithTestcaseDTO

type ChallengeCreateWithTestcaseDTO struct {
	Name        string                 `json:"name" validate:"required,min=3,max=255"`
	Description string                 `json:"description" validate:"max=3000"`
	Testcases   []ChallengeTestcaseDTO `json:"testcases" validate:"required"`
}

func ValidateChallengeCreateWithTestcaseDTO

func ValidateChallengeCreateWithTestcaseDTO(c *fiber.Ctx) ChallengeCreateWithTestcaseDTO

func (*ChallengeCreateWithTestcaseDTO) GetTestcases

type ChallengeExtended

type ChallengeExtended struct {
	Challenge
	User             `json:"user"`
	SubmissionStatus string `json:"submission_status"`
}

type ChallengePaginationOptions

type ChallengePaginationOptions struct {
	PaginationOptions
	User *User
}

type ChallengeTestcase

type ChallengeTestcase struct {
	ID                  uint                  `json:"testcase_id" gorm:"primaryKey"`
	Input               string                `json:"input"`
	ExpectedOutput      string                `json:"expected_output"`
	LimitMemory         uint                  `json:"limit_memory"`
	LimitTimeMs         uint                  `json:"limit_time_ms"`
	SubmissionTestcases []*SubmissionTestcase `json:"submission_testcases"`
	ChallengeID         uint                  `json:"challenge_id"`
	Challenge           *Challenge            `json:"challenge"`
	ActionFlag          string                `json:"-" gorm:"-"`
}

type ChallengeTestcaseDTO

type ChallengeTestcaseDTO struct {
	ID             uint   `json:"testcase_id" validate:"required,number"`
	Input          string `json:"input" validate:"required,max=1024"`
	ExpectedOutput string `json:"expected_output" validate:"required,max=1024"`
	LimitMemory    uint   `json:"limit_memory" validate:"required"`
	LimitTimeMs    uint   `json:"limit_time_ms" validate:"required"`
	Action         string `json:"action" validate:"required,oneof=create update delete"`
}

func (*ChallengeTestcaseDTO) ToTestcase

func (t *ChallengeTestcaseDTO) ToTestcase() *ChallengeTestcase

type ChallengeUpdateDTO

type ChallengeUpdateDTO struct {
	Name        string                 `json:"name" validate:"required,min=3,max=255"`
	Description string                 `json:"description" validate:"max=3000"`
	Testcases   []ChallengeTestcaseDTO `json:"testcases" validate:"required"`
}

func ValidateChallengeUpdateDTO

func ValidateChallengeUpdateDTO(c *fiber.Ctx) ChallengeUpdateDTO

func (*ChallengeUpdateDTO) GetTestcases

func (c *ChallengeUpdateDTO) GetTestcases() []*ChallengeTestcase

type HttpBadRequest

type HttpBadRequest struct {
	Error   string   `json:"error"`
	Message string   `json:"message"`
	Errors  []string `json:"errors"`
}

type HttpError

type HttpError struct {
	Message string `json:"message"`
}

type JWTClaims

type JWTClaims struct {
	UserID      uint   `json:"user_id"`
	DisplayName string `json:"display_name"`
	Email       string `json:"email"`
	Role        string `json:"role"`
	jwt.RegisteredClaims
}

type PaginationOptions

type PaginationOptions struct {
	Page   int    `json:"page" validate:"min=1"`
	Limit  int    `json:"limit" validate:"min=1,max=100"`
	Order  string `json:"order_by" validate:"oneof=asc desc"`
	Sort   string `json:"sort_by" validate:"string,max=20"`
	Search string `json:"search" validate:"string,max=100"`
}

type PaginationResult

type PaginationResult[T any] struct {
	Total int `json:"total"`
	Items []T `json:"items"`
}

type SandboxInstance

type SandboxInstance struct {
	RunID           string
	Language        string
	ImageName       string
	ProgramVolume   volume.Volume
	Instruction     *SandboxInstruction
	CompileExitCode int
	CompileStdout   string
	CompileStderr   string
	Code            string
}

type SandboxInstruction

type SandboxInstruction struct {
	Language       string
	DockerImage    string
	CompileCmd     string
	RunCmd         string
	CompileTimeout uint
}

func GetSandboxInstructionByLanguage

func GetSandboxInstructionByLanguage(language string) *SandboxInstruction

type SandboxRunResult

type SandboxRunResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Timeout  bool
	Err      error
}

type Submission

type Submission struct {
	ID                  uint                  `json:"submission_id" gorm:"primaryKey"`
	Language            string                `json:"language"`
	Code                string                `json:"code"`
	Status              string                `json:"status" gorm:"default:PENDING"`
	UserID              uint                  `json:"user_id"`
	User                *User                 `json:"user"`
	ChallengeID         uint                  `json:"challenge_id"`
	Challenge           *Challenge            `json:"challenge"`
	SubmissionTestcases []*SubmissionTestcase `json:"submission_testcases" gorm:"foreignKey:SubmissionID;constraint:OnDelete:CASCADE"`
}

func (*Submission) IsCorrect

func (s *Submission) IsCorrect() bool

type SubmissionCreateDTO

type SubmissionCreateDTO struct {
	ChallengeID uint   `json:"challenge_id" validate:"required"`
	Language    string `json:"language" validate:"required"`
	Code        string `json:"code" validate:"required"`
}

func ValidateSubmissionCreateDTO

func ValidateSubmissionCreateDTO(c *fiber.Ctx) SubmissionCreateDTO

type SubmissionPaginationOptions

type SubmissionPaginationOptions struct {
	PaginationOptions
	User      *User
	Challenge *Challenge
}

type SubmissionTestcase

type SubmissionTestcase struct {
	ID                  uint               `json:"submission_testcase_id" gorm:"primaryKey"`
	Status              string             `json:"status" gorm:"default:PENDING"`
	Output              string             `json:"output"`
	SubmissionID        uint               `json:"submission_id"`
	Submission          *Submission        `json:"submission"`
	ChallengeTestcaseID uint               `json:"challenge_testcase_id"`
	ChallengeTestcase   *ChallengeTestcase `json:"challenge_testcase" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	Note                string             `json:"note"`
}

type User

type User struct {
	ID          uint      `json:"id" gorm:"primarykey"`
	DisplayName string    `json:"displayname" gorm:"unique;not null"`
	Password    string    `json:"-" gorm:"not null"`
	Email       string    `json:"email" gorm:"unique;not null"`
	Role        string    `json:"role" gorm:"not null;default:USER"`
	CreatedAt   time.Time `json:"-" gorm:"autoCreateTime"`
}

type UserLoginDTO

type UserLoginDTO struct {
	Password string `json:"password" validate:"required,min=6,max=32"`
	Email    string `json:"email" validate:"required,email,min=6,max=50"`
}

func ValidateUserLoginDTO

func ValidateUserLoginDTO(c *fiber.Ctx) UserLoginDTO

type UserLoginResponse

type UserLoginResponse struct {
	Token string `json:"token"`
	UserRegisterResponse
}

type UserRegisterDTO

type UserRegisterDTO struct {
	DisplayName string `json:"displayname" validate:"required,min=3,max=32"`
	Password    string `json:"password" validate:"required,min=6,max=32"`
	Email       string `json:"email" validate:"required,email,min=6,max=50"`
}

func ValidateUserRegisterDTO

func ValidateUserRegisterDTO(c *fiber.Ctx) UserRegisterDTO

type UserRegisterResponse

type UserRegisterResponse struct {
	UserID      uint   `json:"userid"`
	DisplayName string `json:"displayname"`
	Email       string `json:"email"`
	Role        string `json:"role"`
}

type UserUpdateRoleDTO

type UserUpdateRoleDTO struct {
	UserID uint   `json:"userid" validate:"required"`
	Role   string `json:"role" validate:"required,oneof=ADMIN STAFF USER"`
}

func ValidateUserUpdateRoleDTO

func ValidateUserUpdateRoleDTO(c *fiber.Ctx) UserUpdateRoleDTO

Jump to

Keyboard shortcuts

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