feat:
This commit is contained in:
parent
4cdd751b16
commit
be25404852
51 changed files with 606 additions and 1194 deletions
10
internal/models/contest.go
Normal file
10
internal/models/contest.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Contest struct {
|
||||
Id *int32 `db:"id"`
|
||||
Title *string `db:"title"`
|
||||
CreatedAt *time.Time `db:"created_at"`
|
||||
UpdatedAt *time.Time `db:"updated_at"`
|
||||
}
|
13
internal/models/language.go
Normal file
13
internal/models/language.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
package models
|
||||
|
||||
type Language struct {
|
||||
Name string
|
||||
CompileCmd []string //source: src;result:executable
|
||||
RunCmd []string //source: executable
|
||||
}
|
||||
|
||||
var Languages = [...]Language{
|
||||
{Name: "gcc std=c90",
|
||||
CompileCmd: []string{"gcc", "src", "-std=c90", "-o", "executable"},
|
||||
RunCmd: []string{"executable"}},
|
||||
}
|
8
internal/models/participant.go
Normal file
8
internal/models/participant.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package models
|
||||
|
||||
type Participant struct {
|
||||
Id *int32 `db:"id"`
|
||||
UserId *int32 `db:"user_id"`
|
||||
ContestId *int32 `db:"contest_id"`
|
||||
Name *string `db:"name"`
|
||||
}
|
15
internal/models/problem.go
Normal file
15
internal/models/problem.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Problem struct {
|
||||
Id *int32 `db:"id"`
|
||||
Title *string `db:"title"`
|
||||
Content *string `db:"content"`
|
||||
TimeLimit *int32 `db:"time_limit"`
|
||||
MemoryLimit *int32 `db:"memory_limit"`
|
||||
TestingStrategy *int32 `db:"testing_strategy"`
|
||||
TestingOrder *string `db:"testing_order"`
|
||||
CreatedAt *time.Time `db:"created_at"`
|
||||
UpdatedAt *time.Time `db:"updated_at"`
|
||||
}
|
30
internal/models/result.go
Normal file
30
internal/models/result.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Result int32
|
||||
|
||||
const (
|
||||
NotTested Result = 1 // change only with schema change
|
||||
Accepted Result = 2
|
||||
WrongAnswer Result = 3
|
||||
PresentationError Result = 4
|
||||
CompilationError Result = 5
|
||||
MemoryLimitExceeded Result = 6
|
||||
TimeLimitExceeded Result = 7
|
||||
RuntimeError Result = 8
|
||||
SystemFailDuringTesting Result = 9
|
||||
Testing Result = 10
|
||||
)
|
||||
|
||||
var ErrBadResult = errors.New("bad result")
|
||||
|
||||
func (result Result) Valid() error {
|
||||
switch result {
|
||||
case NotTested, Accepted, TimeLimitExceeded, MemoryLimitExceeded, CompilationError, SystemFailDuringTesting:
|
||||
return nil
|
||||
}
|
||||
return ErrBadResult
|
||||
}
|
52
internal/models/role.go
Normal file
52
internal/models/role.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
type Role int32
|
||||
|
||||
const (
|
||||
RoleSpectator Role = 0
|
||||
RoleParticipant Role = 1
|
||||
RoleModerator Role = 2
|
||||
RoleAdmin Role = 3
|
||||
)
|
||||
|
||||
func (role Role) IsAdmin() bool {
|
||||
return role == RoleAdmin
|
||||
}
|
||||
|
||||
func (role Role) IsModerator() bool {
|
||||
return role == RoleModerator
|
||||
}
|
||||
|
||||
func (role Role) IsParticipant() bool {
|
||||
return role == RoleParticipant
|
||||
}
|
||||
|
||||
func (role Role) IsSpectator() bool {
|
||||
return role == RoleSpectator
|
||||
}
|
||||
|
||||
func (role Role) AtLeast(other Role) bool {
|
||||
return role >= other
|
||||
}
|
||||
|
||||
func (role Role) AtMost(other Role) bool {
|
||||
return role <= other
|
||||
}
|
||||
|
||||
var ErrBadRole = errors.New("bad role")
|
||||
|
||||
func (role Role) Valid() error {
|
||||
switch role {
|
||||
case RoleSpectator, RoleParticipant, RoleModerator, RoleAdmin:
|
||||
return nil
|
||||
}
|
||||
return ErrBadRole
|
||||
}
|
||||
|
||||
func (role Role) AsPointer() *Role {
|
||||
return &role
|
||||
}
|
14
internal/models/solution.go
Normal file
14
internal/models/solution.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type Solution struct {
|
||||
Id *int32 `db:"id"`
|
||||
ParticipantId *int32 `db:"participant_id"`
|
||||
TaskId *int32 `db:"task_id"`
|
||||
LanguageId *int32 `db:"language_id"`
|
||||
SolutionHash *string `db:"solution_hash"`
|
||||
Result *int32 `db:"result"`
|
||||
Score *int32 `db:"score"`
|
||||
CreatedAt *time.Time `db:"created_at"`
|
||||
}
|
9
internal/models/task.go
Normal file
9
internal/models/task.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package models
|
||||
|
||||
type Task struct {
|
||||
Id *int32 `db:"id"`
|
||||
ContestId *int32 `db:"contest_id"`
|
||||
ProblemId *int32 `db:"problem_id"`
|
||||
Position *int32 `db:"position"`
|
||||
PositionName *string `db:"position_name"`
|
||||
}
|
9
internal/models/user.go
Normal file
9
internal/models/user.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type User struct {
|
||||
UserId *int32 `json:"user_id" db:"user_id"`
|
||||
Role *Role `json:"role" db:"role"`
|
||||
UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue