models

package
v0.0.0-...-5c5c951 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const PriorityDefault = uint8(127)

Variables

This section is empty.

Functions

This section is empty.

Types

type Class

type Class struct {
	ID          uint    `gorm:"primaryKey" json:"id"`
	Name        string  `json:"name" gorm:"size:255;default:'';not null"`
	CourseName  string  `json:"course_name" gorm:"size:255;default:'';not null"`
	Description string  `json:"description"`
	InviteCode  string  `json:"invite_code" gorm:"size:255;default:'';not null"`
	Managers    []*User `json:"managers" gorm:"many2many:user_manage_classes"`
	Students    []*User `json:"students" gorm:"many2many:user_in_classes"`

	ProblemSets []*ProblemSet `json:"problem_sets"`

	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"`
}

func (*Class) AddStudents

func (c *Class) AddStudents(ids []uint) error

func (*Class) AfterDelete

func (c *Class) AfterDelete(tx *gorm.DB) error

func (*Class) DeleteStudents

func (c *Class) DeleteStudents(ids []uint) error

func (Class) GetID

func (c Class) GetID() uint

func (Class) TypeName

func (c Class) TypeName() string

type Config

type Config struct {
	ID        uint `gorm:"primaryKey"`
	Key       string
	Value     *string `gorm:"default:''"` // 可能是空字符串, 因此得是指针
	CreatedAt time.Time
	UpdatedAt time.Time
}

type EmailVerificationToken

type EmailVerificationToken struct {
	ID     uint `gorm:"primaryKey" json:"id"`
	UserID uint
	User   *User
	Email  string
	Token  string

	Used bool

	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

type Grade

type Grade struct {
	ID uint `gorm:"primaryKey" json:"id"`

	UserID       uint        `json:"user_id"`
	User         *User       `json:"user"`
	ProblemSetID uint        `json:"problem_set_id"`
	ProblemSet   *ProblemSet `json:"problem_set"`
	ClassID      uint        `json:"class_id"`
	Class        *Class      `json:"class"`

	Detail datatypes.JSON `json:"detail"`
	Total  uint           `json:"total"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"-"`
}

func (*Grade) BeforeSave

func (g *Grade) BeforeSave(tx *gorm.DB) (err error)

type HasRole

type HasRole interface {
	GetID() uint
	TypeName() string
}

type Image

type Image struct {
	ID        uint   `gorm:"primaryKey" json:"id"`
	Filename  string `gorm:"filename"`
	FilePath  string `gorm:"filepath"`
	UserID    uint
	User      User
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Language

type Language struct {
	Name             string               `gorm:"primaryKey" json:"name"`
	ExtensionAllowed database.StringArray `gorm:"type:string" json:"extension_allowed"`
	BuildScriptName  string               `json:"-"`
	BuildScript      *Script              `gorm:"foreignKey:BuildScriptName" json:"build_script"`
	RunScriptName    string               `json:"-"`
	RunScript        *Script              `gorm:"foreignKey:RunScriptName" json:"run_script"`
	CreatedAt        time.Time            `json:"created_at"`
	UpdatedAt        time.Time            `json:"updated_at"`
}

type Permission

type Permission struct {
	ID     uint   `gorm:"primaryKey" json:"id"`
	RoleID uint   `json:"role_id"`
	Name   string `json:"name"`
}

type Problem

type Problem struct {
	ID                 uint   `gorm:"primaryKey" json:"id"`
	Name               string `sql:"index" json:"name" gorm:"size:255;default:'';not null"`
	Description        string `json:"description"`
	AttachmentFileName string `json:"attachment_file_name" gorm:"size:255;default:'';not null"`
	Public             bool   `json:"public" gorm:"default:false;not null"`
	Privacy            bool   `json:"privacy" gorm:"default:false;not null"`

	MemoryLimit       uint64               `json:"memory_limit" gorm:"default:0;not null;type:bigint"`               // Byte
	TimeLimit         uint                 `json:"time_limit" gorm:"default:0;not null"`                             // ms
	LanguageAllowed   database.StringArray `json:"language_allowed" gorm:"size:255;default:'';not null;type:string"` // E.g.    cpp,c,java,python
	BuildArg          string               `json:"build_arg" gorm:"size:2047;default:'';not null"`                   // E.g.  O2=false
	CompareScriptName string               `json:"compare_script_name" gorm:"default:0;not null"`
	CompareScript     Script               `json:"compare_script"`

	TestCases []TestCase `json:"test_cases"`
	Tags      []Tag      `json:"tags" gorm:"OnDelete:CASCADE"`

	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

func (*Problem) AfterDelete

func (p *Problem) AfterDelete(tx *gorm.DB) (err error)

func (Problem) GetID

func (p Problem) GetID() uint

func (*Problem) LoadTags

func (p *Problem) LoadTags()

func (*Problem) LoadTestCases

func (p *Problem) LoadTestCases()

func (Problem) TypeName

func (p Problem) TypeName() string

type ProblemSet

type ProblemSet struct {
	ID uint `gorm:"primaryKey" json:"id"`

	ClassID     uint   `sql:"index" json:"class_id" gorm:"not null"`
	Class       *Class `json:"class"`
	Name        string `json:"name" gorm:"not null;size:255"`
	Description string `json:"description"`

	Problems []*Problem `json:"problems" gorm:"many2many:problems_in_problem_sets"`
	Grades   []*Grade   `json:"grades"`

	StartTime time.Time `json:"start_time"`
	EndTime   time.Time `json:"end_time"`

	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

func (*ProblemSet) AddProblems

func (p *ProblemSet) AddProblems(ids []uint) error

func (*ProblemSet) AfterDelete

func (p *ProblemSet) AfterDelete(tx *gorm.DB) error

func (*ProblemSet) DeleteProblems

func (p *ProblemSet) DeleteProblems(ids []uint) error

type ProblemTag

type ProblemTag struct {
	ID        uint `gorm:"primaryKey" json:"id"`
	ProblemID uint `gorm:"index"`
	Name      string
	CreatedAt time.Time `json:"created_at"`
}

type Role

type Role struct {
	ID          uint    `gorm:"primaryKey" json:"id"`
	Name        string  `json:"name"`
	Target      *string `json:"target"`
	Permissions []Permission
}

func (*Role) AddPermission

func (r *Role) AddPermission(name string) (err error)

type Run

type Run struct {
	ID uint `gorm:"primaryKey" json:"id"`

	UserID       uint        `sql:"index" json:"user_id"`
	User         *User       `json:"user"`
	ProblemID    uint        `sql:"index" json:"problem_id"`
	Problem      *Problem    `json:"problem"`
	ProblemSetID uint        `sql:"index" json:"problem_set_id"`
	TestCaseID   uint        `json:"test_case_id"`
	TestCase     *TestCase   `json:"test_case"`
	Sample       bool        `json:"sample" gorm:"not null"`
	SubmissionID uint        `json:"submission_id"`
	Submission   *Submission `json:"submission"`
	Priority     uint8       `json:"priority"`

	Judged        bool `json:"judged"`
	JudgerName    string
	JudgerMessage string

	/*
		PENDING / JUDGING / JUDGEMENT_FAILED / NO_COMMENT
		ACCEPTED / WRONG_ANSWER / RUNTIME_ERROR / TIME_LIMIT_EXCEEDED / MEMORY_LIMIT_EXCEEDED / DANGEROUS_SYSTEM_CALLS
	*/
	Status             string `json:"status"`
	MemoryUsed         uint   `json:"memory_used"` // Byte
	TimeUsed           uint   `json:"time_used"`   // ms
	OutputStrippedHash string `json:"output_stripped_hash"`

	CreatedAt time.Time      `sql:"index" json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

type Script

type Script struct {
	Name      string    `gorm:"primaryKey" json:"name"`
	Filename  string    `json:"file_name"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Submission

type Submission struct {
	ID uint `gorm:"primaryKey" json:"id"`

	UserID       uint        `sql:"index" json:"user_id"`
	User         *User       `json:"user"`
	ProblemID    uint        `sql:"index" json:"problem_id"`
	Problem      *Problem    `json:"problem"`
	ProblemSetID uint        `sql:"index" json:"problem_set_id"`
	ProblemSet   *ProblemSet `json:"problem_set"`
	LanguageName string      `json:"language_name"`
	Language     *Language   `json:"language"`
	FileName     string      `json:"file_name"`
	Priority     uint8       `json:"priority"`

	Judged bool `json:"judged"`
	Score  uint `json:"score"`

	/*
		PENDING  / JUDGEMENT_FAILED / NO_COMMENT
		ACCEPTED / WRONG_ANSWER / RUNTIME_ERROR / TIME_LIMIT_EXCEEDED / MEMORY_LIMIT_EXCEEDED / DANGEROUS_SYSTEM_CALLS
	*/
	Status string `json:"status"`

	Runs []Run `json:"runs"`

	CreatedAt time.Time      `sql:"index" json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

func (*Submission) AfterDelete

func (s *Submission) AfterDelete(tx *gorm.DB) (err error)

func (*Submission) LoadRuns

func (s *Submission) LoadRuns()

type Tag

type Tag struct {
	ID        uint `gorm:"primaryKey" json:"id"`
	ProblemID uint
	Name      string
	CreatedAt time.Time `json:"created_at"`
}

type TestCase

type TestCase struct {
	ID uint `gorm:"primaryKey" json:"id"`

	ProblemID uint `sql:"index" json:"problem_id" gorm:"not null"`
	Score     uint `json:"score" gorm:"default:0;not null"` // 0 for 平均分配
	Sample    bool `json:"sample" gorm:"default:false;not null"`

	InputFileName  string `json:"input_file_name" gorm:"size:255;default:'';not null"`
	OutputFileName string `json:"output_file_name" gorm:"size:255;default:'';not null"`

	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

func (*TestCase) AfterDelete

func (t *TestCase) AfterDelete(tx *gorm.DB) (err error)

type Token

type Token struct {
	ID         uint   `gorm:"primaryKey" json:"id"`
	Token      string `gorm:"unique_index" json:"token"`
	UserID     uint
	User       User
	RememberMe bool      `json:"remember_me"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

type User

type User struct {
	ID       uint   `gorm:"primaryKey" json:"id"`
	Username string `gorm:"unique_index" json:"username" validate:"required,max=30,min=5,username"`
	Nickname string `gorm:"index:nickname" json:"nickname"`
	Email    string `gorm:"unique_index" json:"email"`
	Password string `json:"-"`

	EmailVerified bool `json:"email_verified"`

	Roles      []UserHasRole `json:"roles"`
	RoleLoaded bool          `gorm:"-" json:"-"`

	ClassesManaging []*Class `json:"class_managing" gorm:"many2many:user_manage_classes"`
	ClassesTaking   []*Class `json:"class_taking" gorm:"many2many:user_in_classes"`

	Grades []*Grade `json:"grades"`

	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"-"`
	DeletedAt gorm.DeletedAt `sql:"index" json:"deleted_at"`

	Credentials []WebauthnCredential
}

func (*User) Can

func (u *User) Can(permission string, target ...HasRole) bool

func (*User) DeleteRole

func (u *User) DeleteRole(name string, target ...HasRole)

func (*User) GrantRole

func (u *User) GrantRole(name string, target ...HasRole)

func (*User) HasRole

func (u *User) HasRole(name string, target ...HasRole) bool

func (*User) In

func (u *User) In(users []User) bool

In just compare ID to judge if a user is in a user slice

func (*User) LoadRoles

func (u *User) LoadRoles()

func (*User) WebAuthnCredentials

func (u *User) WebAuthnCredentials() []webauthn.Credential

func (*User) WebAuthnDisplayName

func (u *User) WebAuthnDisplayName() string

func (*User) WebAuthnID

func (u *User) WebAuthnID() (ret []byte)

func (*User) WebAuthnIcon

func (u *User) WebAuthnIcon() string

func (*User) WebAuthnName

func (u *User) WebAuthnName() string

type UserHasRole

type UserHasRole struct {
	ID       uint `gorm:"primaryKey" json:"id"`
	UserID   uint `json:"user_id"`
	RoleID   uint `json:"role_id"`
	Role     Role `json:"role"`
	TargetID uint `json:"target_id"`
}

func (UserHasRole) MarshalJSON

func (u UserHasRole) MarshalJSON() ([]byte, error)

type WebauthnCredential

type WebauthnCredential struct {
	ID        uint `gorm:"primaryKey" json:"id"`
	UserID    uint
	Content   string
	CreatedAt time.Time `json:"created_at"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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