models

package
v0.0.0-...-fe69d71 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2019 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EmailConfirmationTokenLifetime = 7 * 24 * time.Hour
)
View Source
const PasswordResetTokenLifeTime = 30 * time.Minute
View Source
const (
	WhiteEmailPermanentLifeTime time.Duration = -1
)

Variables

View Source
var (
	ErrNilArgument                         = errors.New("nil argument(s)")
	ErrInvalidFileNameOrDirectoryStructure = errors.New("ファイルの命名かディレクトリの構造が正しくありません。")
)
View Source
var (
	ErrUserIDIsZero          = errors.New("User IDが0です")
	ErrUserNameAlreadyExists = errors.New("user nameはすでに使用されています")
	ErrEmailAlreadyExists    = errors.New("emailはすでに使用されています")
)
View Source
var (
	ErrLogin               = errors.New("incorrect username or password")
	ErrSessionCreateFailed = errors.New("retry limit exceeded")
)
View Source
var ErrInvalidToken = errors.New("invalid password reset token")
View Source
var ErrParseOutput = errors.New("stdout parse error")

Functions

func CanEditContest

func CanEditContest(contestID, userID uint) bool

func DefaultString

func DefaultString(value, def string) string

func DeleteWhiteEmail

func DeleteWhiteEmail(id uint) error

func EqualTime

func EqualTime(t1, t2 time.Time) bool

func GetBcryptCost

func GetBcryptCost() int

func GetWorkers

func GetWorkers() ([]*work.WorkerObservation, error)

func InitDB

func InitDB()

func InitJobs

func InitJobs()

func IsContestParticipant

func IsContestParticipant(contestID, userID uint) (bool, error)

func IsContestWriter

func IsContestWriter(contestID, userID uint) (bool, error)

func MaxDuration

func MaxDuration(a, b time.Duration) time.Duration

func MaxInt

func MaxInt(a, b int) int

func MaxLong

func MaxLong(a, b int64) int64

func MinInt

func MinInt(a, b int) int

func NewContest

func NewContest(out *Contest) error

func NewProblem

func NewProblem(problem *Problem) error

func ResetPassword

func ResetPassword(token, password string) error

func StartEmailConfirmation

func StartEmailConfirmation(email *WhiteEmail) error

func StartPasswordReset

func StartPasswordReset(user *User) error

func StopPool

func StopPool()

func Submit

func Submit(submission *Submission) error

Types

type Authority

type Authority uint
const (
	Member Authority = 0
	Admin  Authority = 1
)

type CaseSet

type CaseSet struct {
	ID        uint       `gorm:"primary_key" json:"id"`
	CreatedAt time.Time  `json:"createdAt"`
	UpdatedAt time.Time  `json:"updatedAt"`
	DeletedAt *time.Time `sql:"index" json:"-"`
	ProblemID uint       `gorm:"not null" json:"problemID"`
	Point     int        `gorm:"not null; default:'0'" json:"point"`
	TestCases []TestCase `json:"-"`
}

func GetCaseSet

func GetCaseSet(id uint) *CaseSet

func (*CaseSet) Delete

func (s *CaseSet) Delete()

func (*CaseSet) DeletePermanently

func (s *CaseSet) DeletePermanently()

func (*CaseSet) FetchTestCases

func (s *CaseSet) FetchTestCases()

func (*CaseSet) UpdatePoint

func (s *CaseSet) UpdatePoint(point int)

type Contest

type Contest struct {
	ID                   uint                  `gorm:"primary_key" json:"id"`
	CreatedAt            time.Time             `json:"createdAt"`
	UpdatedAt            time.Time             `json:"updatedAt"`
	DeletedAt            *time.Time            `sql:"index" json:"-"`
	Title                string                `json:"title"`
	Description          string                `gorm:"type:text" json:"description"`
	StartAt              time.Time             `json:"startAt"`
	EndAt                time.Time             `json:"endAt"`
	Writers              []User                `gorm:"many2many:contests_writers;" json:"writers"`
	Participants         []User                `gorm:"many2many:contests_participants;" json:"-"`
	ContestsParticipants []ContestsParticipant `json:"participants"`
	Problems             []Problem             `json:"problems"`
	Duration             *time.Duration        `json:"duration"`
}

func GetAllContests

func GetAllContests() ([]Contest, error)

func GetContest

func GetContest(id uint) *Contest

func GetContestDeeply

func GetContestDeeply(id uint, session *UserSession) *Contest

func (*Contest) AddParticipant

func (c *Contest) AddParticipant(userID uint) error

func (*Contest) CanEdit

func (c *Contest) CanEdit(s *UserSession) bool

func (*Contest) CanViewProblems

func (c *Contest) CanViewProblems(s *UserSession) (bool, error)

func (*Contest) Ended

func (c *Contest) Ended(t time.Time, s *UserSession) (bool, error)

func (*Contest) FetchParticipants

func (c *Contest) FetchParticipants()

func (*Contest) FetchProblems

func (c *Contest) FetchProblems()

func (*Contest) FetchWriters

func (c *Contest) FetchWriters()

func (*Contest) GetStandings

func (c *Contest) GetStandings(session *UserSession) ([]Score, error)

func (*Contest) GetSubmissions

func (c *Contest) GetSubmissions(session *UserSession, limit, page int, userID, problemID *uint) ([]Submission, int, error)

func (*Contest) IsOpen

func (c *Contest) IsOpen(t time.Time, s *UserSession) (bool, error)

コンテストが時刻tのとき開催中であればtrueを返します。

func (*Contest) IsParticipant

func (c *Contest) IsParticipant(userID uint) (bool, error)

func (*Contest) IsWriter

func (c *Contest) IsWriter(userID uint) (bool, error)

func (*Contest) Started

func (c *Contest) Started(t time.Time, s *UserSession) (bool, error)

func (*Contest) Update

func (c *Contest) Update() error

func (*Contest) UpdateWriters

func (c *Contest) UpdateWriters() error

type ContestJudgementStatus

type ContestJudgementStatus struct {
	UserID    uint            `gorm:"primary_key" sql:"type:int unsigned" json:"userID"`
	ProblemID uint            `gorm:"primary_key" sql:"type:int unsigned" json:"problemID"`
	ContestID uint            `gorm:"not null" json:"contestID"`
	CreatedAt time.Time       `json:"createdAt"`
	UpdatedAt time.Time       `json:"updatedAt"`
	Status    JudgementStatus `gorm:"not null; default:'0'" json:"status"`
	Point     int             `gorm:"not null; default:'0'" json:"point"`
}

func GetContestJudgementStatuses

func GetContestJudgementStatuses(contestID uint, userID uint) ([]ContestJudgementStatus, error)

type ContestsParticipant

type ContestsParticipant struct {
	CreatedAt time.Time `gorm:"default:'1971-01-01 00:00:00'" json:"createdAt"`
	ContestID uint      `gorm:"not null" json:"contestID"`
	UserID    uint      `gorm:"not null" json:"userID"`
	User      User      `json:"user" json:"user"`
}

func (*ContestsParticipant) FetchUser

func (p *ContestsParticipant) FetchUser()

type EmailConfirmation

type EmailConfirmation struct {
	ID           uint          `gorm:"primary_key" json:"id"`
	CreatedAt    time.Time     `json:"createdAt"`
	UpdatedAt    time.Time     `json:"updatedAt"`
	LifeTime     time.Duration `json:"lifeTime"`
	Token        string        `gorm:"not null; index" json:"-"`
	WhiteEmailID uint          `gorm:"not null" json:"whiteEmailID"`
	WhiteEmail   WhiteEmail    `json:"whiteEmail"`
}

func GetEmailConfirmation

func GetEmailConfirmation(token string) *EmailConfirmation

func (*EmailConfirmation) FetchWhiteEmail

func (c *EmailConfirmation) FetchWhiteEmail()

type ErrJudgeSourceCodeCompile

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

func (ErrJudgeSourceCodeCompile) Error

type JudgeResult

type JudgeResult struct {
	ID               uint            `gorm:"primary_key" json:"id"`
	CreatedAt        time.Time       `json:"createdAt"`
	UpdatedAt        time.Time       `json:"updatedAt"`
	JudgeSetResultID uint            `gorm:"not null" json:"-"`
	TestCase         TestCase        `json:"-"`
	TestCaseID       uint            `gorm:"not null" json:"-"`
	Status           JudgementStatus `gorm:"not null; default:'0'" json:"status"`
	ExecTime         time.Duration   `json:"execTime"`
	MemoryUsage      int64           `json:"memoryUsage"`
}

func (*JudgeResult) Delete

func (r *JudgeResult) Delete()

func (*JudgeResult) FetchTestCase

func (r *JudgeResult) FetchTestCase()

type JudgeSetResult

type JudgeSetResult struct {
	ID           uint            `gorm:"primary_key" json:"id"`
	CreatedAt    time.Time       `json:"createdAt"`
	UpdatedAt    time.Time       `json:"updatedAt"`
	SubmissionID uint            `gorm:"not null" json:"-"`
	CaseSet      CaseSet         `json:"caseSet"`
	CaseSetID    uint            `gorm:"not null" json:"caseSetID"`
	Point        int             `json:"point"`
	Status       JudgementStatus `gorm:"not null; default:'0'" json:"status"`
	JudgeResults []JudgeResult   `json:"judgeResults"`
	ExecTime     time.Duration   `json:"execTime"`
	MemoryUsage  int64           `json:"memoryUsage"`
}

func (*JudgeSetResult) Delete

func (r *JudgeSetResult) Delete()

func (*JudgeSetResult) FetchCaseSet

func (r *JudgeSetResult) FetchCaseSet()

func (*JudgeSetResult) FetchJudgeResults

func (r *JudgeSetResult) FetchJudgeResults(sorted bool)

func (*JudgeSetResult) GetJudgeResultsSorted

func (r *JudgeSetResult) GetJudgeResultsSorted() []JudgeResult

type JudgeType

type JudgeType int
const (
	// inputとoutputが1対1の普通のジャッジ
	JudgeTypeNormal JudgeType = 0
	// 誤差許容
	JudgeTypePrecision JudgeType = 1
	// 特別なoutputの評価器が必要なジャッジ
	JudgeTypeSpecial JudgeType = 2
)

type JudgementConfig

type JudgementConfig struct {
	ID              uint      `gorm:"primary_key" json:"id"`
	CreatedAt       time.Time `json:"-"`
	UpdatedAt       time.Time `json:"-"`
	ProblemID       *uint     `json:"-"`
	JudgeSourceCode *string   `gorm:"type:text" json:"judgeSourceCode,omitempty"`
	LanguageID      *uint     `json:"languageID,omitempty"`
	Language        *Language `json:"language,omitempty"`
	Difference      float64   `json:"difference"`
}

func (*JudgementConfig) FetchLanguage

func (d *JudgementConfig) FetchLanguage()

type JudgementStatus

type JudgementStatus int
const (
	StatusInQueue             JudgementStatus = 0
	StatusJudging             JudgementStatus = 1
	StatusAccepted            JudgementStatus = 2
	StatusPresentationError   JudgementStatus = 3
	StatusWrongAnswer         JudgementStatus = 4
	StatusTimeLimitExceeded   JudgementStatus = 5
	StatusMemoryLimitExceeded JudgementStatus = 6
	StatusRuntimeError        JudgementStatus = 7
	StatusCompileError        JudgementStatus = 8
	StatusOutputLimitExceeded JudgementStatus = 9
	StatusUnknownError        JudgementStatus = 10
)

type Language

type Language struct {
	ID             uint      `gorm:"primary_key" json:"id"`
	CreatedAt      time.Time `json:"-"`
	UpdatedAt      time.Time `json:"-"`
	ImageName      string    `gorm:"not null" json:"-"`
	DisplayName    string    `gorm:"not null; unique_index" json:"displayName"`
	FileName       string    `gorm:"not null" json:"-"`
	ExeFileName    string    `gorm:"not null" json:"-"`
	CompileCommand string    `gorm:"not null" json:"compileCommand"`
	ExecCommand    string    `gorm:"not null" json:"execCommand"`
}

func GetAllLanguages

func GetAllLanguages() []*Language

func GetLanguage

func GetLanguage(id uint) *Language

func (Language) GetCompileCommandSlice

func (l Language) GetCompileCommandSlice() []string

func (Language) GetExecCommandSlice

func (l Language) GetExecCommandSlice() []string

type PasswordResetToken

type PasswordResetToken struct {
	ID        uint      `gorm:"primary_key" json:"-"`
	CreatedAt time.Time `json:"-"`
	Token     string    `gorm:"index; not null"`
	UserID    uint      `gorm:"not null"`
	User      User
}

func GetPasswordResetToken

func GetPasswordResetToken(token string) *PasswordResetToken

func (*PasswordResetToken) FetchUser

func (t *PasswordResetToken) FetchUser()

type Problem

type Problem struct {
	ID              uint             `gorm:"primary_key" json:"id"`
	WriterID        uint             `gorm:"not null" json:"writerID"`
	Writer          User             `gorm:"ForeignKey:WriterID" json:"writer,omitempty"`
	CreatedAt       time.Time        `json:"createdAt"`
	UpdatedAt       time.Time        `json:"updatedAt"`
	Title           string           `gorm:"not null" json:"title"`
	Body            string           `gorm:"type:text; not null" json:"body"`
	InputFormat     string           `gorm:"type:text" json:"inputFormat"`
	OutputFormat    string           `gorm:"type:text" json:"outputFormat"`
	Constraints     string           `gorm:"type:text" json:"constraints"`
	Samples         []Sample         `json:"samples,omitempty"`
	TimeLimit       time.Duration    `gorm:"not null" json:"timeLimit" validate:"required,max=60000000000,min=1000000000"`
	MemoryLimit     int              `gorm:"not null" json:"memoryLimit" validate:"required,max=512,min=128"`
	JudgeType       JudgeType        `gorm:"not null; default:'0'" json:"judgeType" validate:"max=2,min=0"`
	CaseSets        []CaseSet        `json:"caseSets,omitempty"`
	Submissions     []Submission     `json:"-"`
	Contest         *Contest         `json:"contest,omitempty"`
	ContestID       *uint            `json:"contestID"`
	JudgementConfig *JudgementConfig `json:"judgementConfig,omitempty"`
}

func GetNoContestProblems

func GetNoContestProblems() []Problem

func GetProblem

func GetProblem(id uint) *Problem

func GetProblems

func GetProblems(contestID *uint, minID, maxID uint, count int) []Problem

func (*Problem) CanEdit

func (p *Problem) CanEdit(s *UserSession) bool

func (*Problem) CanView

func (p *Problem) CanView(s *UserSession) bool

func (*Problem) Delete

func (p *Problem) Delete()

func (*Problem) DeleteSamples

func (p *Problem) DeleteSamples()

func (*Problem) FetchCaseSets

func (p *Problem) FetchCaseSets()

func (*Problem) FetchContest

func (p *Problem) FetchContest()

func (*Problem) FetchJudgementConfig

func (p *Problem) FetchJudgementConfig()

func (*Problem) FetchSamples

func (p *Problem) FetchSamples()

func (*Problem) FetchSubmissions

func (p *Problem) FetchSubmissions()

func (*Problem) FetchWriter

func (p *Problem) FetchWriter()

func (*Problem) GetSubmissionsReversed

func (p *Problem) GetSubmissionsReversed() []Submission

func (*Problem) Rejudge

func (p *Problem) Rejudge() error

func (*Problem) ReplaceTestCases

func (p *Problem) ReplaceTestCases(archive []byte) error

func (*Problem) Update

func (p *Problem) Update(request *Problem)

func (*Problem) UpdateSamples

func (p *Problem) UpdateSamples()

type Sample

type Sample struct {
	ID          uint   `gorm:"primary_key" json:"-"`
	ProblemID   uint   `gorm:"not null" json:"problemID"`
	Input       string `gorm:"type:text" json:"input"`
	Output      string `gorm:"type:text" json:"output"`
	Description string `gorm:"type:text" json:"description"`
}

func (*Sample) Delete

func (s *Sample) Delete()

type Score

type Score struct {
	ID           uint          `gorm:"primary_key" json:"id"`
	CreatedAt    time.Time     `json:"createdAt"`
	UpdatedAt    time.Time     `json:"updatedAt"`
	Point        int           `json:"point"`
	UserID       uint          `gorm:"not null" json:"userID"`
	ContestID    uint          `gorm:"not null" json:"-"`
	ScoreDetails []ScoreDetail `json:"details"`
	ScoreTime    time.Duration `gorm:"-" json:"scoreTime"`
}

func (*Score) FetchDetails

func (s *Score) FetchDetails()

type ScoreDetail

type ScoreDetail struct {
	ID         uint          `gorm:"primary_key" json:"id"`
	CreatedAt  time.Time     `json:"createdAt"`
	UpdatedAt  time.Time     `json:"updatedAt"`
	Point      int           `json:"point"`
	WrongCount int           `gorm:"not null" json:"wrongCount"`
	Accepted   bool          `gorm:"not null" json:"accepted"`
	ScoreID    uint          `gorm:"not null" json:"-"`
	ProblemID  uint          `gorm:"not null" json:"problemID"`
	ScoreTime  time.Duration `gorm:"-" json:"scoreTime"`
}

type Submission

type Submission struct {
	ID              uint             `gorm:"primary_key" json:"id"`
	CreatedAt       time.Time        `json:"createdAt"`
	UpdatedAt       time.Time        `json:"updatedAt"`
	UserID          uint             `gorm:"not null" json:"userID"`
	User            User             `json:"user"`
	ProblemID       uint             `gorm:"not null" json:"problemID"`
	Problem         Problem          `json:"problem"`
	LanguageID      uint             `gorm:"not null" json:"languageID"`
	Language        Language         `json:"language"`
	SourceCode      string           `gorm:"type:text; not null" json:"sourceCode"`
	Point           int              `json:"point"`
	Status          JudgementStatus  `gorm:"default:'0'" json:"status"`
	ErrorLog        string           `gorm:"type:text" json:"errorLog"`
	ExecTime        time.Duration    `json:"execTime"`
	MemoryUsage     int64            `json:"memoryUsage"`
	CodeBytes       uint             `json:"codeBytes"`
	JudgeSetResults []JudgeSetResult `json:"judgeSetResults,omitempty"`
	ContestID       *uint            `json:"-"`
}

func GetSubmission

func GetSubmission(submissionID uint) *Submission

func (*Submission) CanView

func (s *Submission) CanView(session *UserSession) bool

func (*Submission) Delete

func (s *Submission) Delete()

func (*Submission) FetchJudgeSetResults

func (s *Submission) FetchJudgeSetResults(sorted bool)

func (*Submission) FetchJudgeSetResultsDeeply

func (s *Submission) FetchJudgeSetResultsDeeply(sorted bool)

func (*Submission) FetchJudgeSetResultsDeeplyForContest

func (s *Submission) FetchJudgeSetResultsDeeplyForContest(session *UserSession) error

func (*Submission) FetchLanguage

func (s *Submission) FetchLanguage()

func (*Submission) FetchProblem

func (s *Submission) FetchProblem()

func (*Submission) FetchUser

func (s *Submission) FetchUser()

func (*Submission) IsWrong

func (s *Submission) IsWrong() bool

func (*Submission) SetStatus

func (s *Submission) SetStatus(status JudgementStatus) error

type TestCase

type TestCase struct {
	gorm.Model
	CaseSetID uint   `gorm:"not null"`
	Input     string `gorm:"type:longtext; not null"`
	Output    string `gorm:"type:longtext; not null"`
}

func (TestCase) Delete

func (c TestCase) Delete()

func (TestCase) DeletePermanently

func (c TestCase) DeletePermanently()

type User

type User struct {
	ID             uint       `gorm:"primary_key" json:"id"`
	CreatedAt      time.Time  `json:"-"`
	UpdatedAt      time.Time  `json:"-"`
	DeletedAt      *time.Time `sql:"index" json:"-"`
	Name           string     `gorm:"not null;unique_index" json:"name"`
	DisplayName    string     `gorm:"not null" json:"displayName"`
	Email          string     `gorm:"not null;unique_index" json:"email,omitempty"`
	Authority      Authority  `gorm:"not null" json:"authority"`
	IsDeleted      bool       `gorm:"not null;default:'0'" json:"-"`
	PasswordDigest string     `gorm:"not null" json:"-"`
}

func FindUserByEmail

func FindUserByEmail(email string) *User

func FindUserByName

func FindUserByName(name string, email bool) *User

func GetAllUsers

func GetAllUsers(email bool) []User

func GetUser

func GetUser(id uint, email bool) *User

func NewUser

func NewUser(name, displayName, email, password string, token *EmailConfirmation) (*User, error)

func UniqueUsers

func UniqueUsers(users []User) []User

func (*User) IsAdmin

func (u *User) IsAdmin() bool

func (*User) IsCorrectPassword

func (u *User) IsCorrectPassword(password string) bool

func (*User) SetPassword

func (u *User) SetPassword(password string, notification bool) error

type UserSession

type UserSession struct {
	ID          uint `gorm:"primary_key"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
	User        User
	UserID      uint   `gorm:"not null"`
	TokenDigest string `gorm:"not null"`
}

func CheckLogin

func CheckLogin(token string) *UserSession

func GetSession

func GetSession(id uint) *UserSession

func NewSession

func NewSession(email, password string) (*UserSession, string, error)

emailとpasswordが正しければ新しいUserSessionとTokenを返す

func (*UserSession) Delete

func (s *UserSession) Delete()

func (*UserSession) FetchUser

func (s *UserSession) FetchUser()

type WhiteEmail

type WhiteEmail struct {
	ID          uint          `gorm:"primary_key" json:"id"`
	CreatedAt   time.Time     `json:"createdAt"`
	UpdatedAt   time.Time     `json:"updatedAt"`
	LifeTime    time.Duration `json:"lifeTime"`
	Email       string        `gorm:"not null; unique_index" json:"email"`
	CreatedByID uint          `gorm:"not null" json:"createdByID"`
	CreatedBy   User          `gorm:"ForeignKey:CreatedByID" json:"createdBy"`
}

func GetWhiteEmail

func GetWhiteEmail(email string) *WhiteEmail

func GetWhiteEmails

func GetWhiteEmails() []WhiteEmail

func NewWhiteEmail

func NewWhiteEmail(email string, user *User) *WhiteEmail

func (*WhiteEmail) FetchCreatedBy

func (e *WhiteEmail) FetchCreatedBy(email bool)

Jump to

Keyboard shortcuts

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