From 50d6f4a81f1faa41db8afb45d39df240ed6ad609 Mon Sep 17 00:00:00 2001 From: dragonmuffin Date: Mon, 23 Sep 2024 23:39:28 +0500 Subject: [PATCH] move models to other repo --- pkg/models/contest.go | 10 -------- pkg/models/language.go | 14 ----------- pkg/models/participant.go | 8 ------ pkg/models/problem.go | 13 ---------- pkg/models/result.go | 31 ----------------------- pkg/models/role.go | 53 --------------------------------------- pkg/models/solution.go | 14 ----------- pkg/models/subtask.go | 8 ------ pkg/models/task.go | 9 ------- pkg/models/testgroup.go | 34 ------------------------- pkg/models/user.go | 9 ------- 11 files changed, 203 deletions(-) delete mode 100644 pkg/models/contest.go delete mode 100644 pkg/models/language.go delete mode 100644 pkg/models/participant.go delete mode 100644 pkg/models/problem.go delete mode 100644 pkg/models/result.go delete mode 100644 pkg/models/role.go delete mode 100644 pkg/models/solution.go delete mode 100644 pkg/models/subtask.go delete mode 100644 pkg/models/task.go delete mode 100644 pkg/models/testgroup.go delete mode 100644 pkg/models/user.go diff --git a/pkg/models/contest.go b/pkg/models/contest.go deleted file mode 100644 index 40a4e2b..0000000 --- a/pkg/models/contest.go +++ /dev/null @@ -1,10 +0,0 @@ -package models - -import "time" - -type Contest struct { - Id *int `db:"id"` - Name *string `db:"name"` - CreatedAt *time.Time `db:"created_at"` - UpdatedAt *time.Time `db:"updated_at"` -} diff --git a/pkg/models/language.go b/pkg/models/language.go deleted file mode 100644 index da0b1b6..0000000 --- a/pkg/models/language.go +++ /dev/null @@ -1,14 +0,0 @@ -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"}}, -} - diff --git a/pkg/models/participant.go b/pkg/models/participant.go deleted file mode 100644 index 8db6814..0000000 --- a/pkg/models/participant.go +++ /dev/null @@ -1,8 +0,0 @@ -package models - -type Participant struct { - Id *int32 `db:"id"` - UserId *int32 `db:"user_id"` - ContestId *int32 `db:"contest_id"` - Name *string `db:"name"` -} diff --git a/pkg/models/problem.go b/pkg/models/problem.go deleted file mode 100644 index 80fbe9c..0000000 --- a/pkg/models/problem.go +++ /dev/null @@ -1,13 +0,0 @@ -package models - -import "time" - -type Problem struct { - Id *int32 `db:"id"` - Name *string `db:"name"` - Description *string `db:"description"` - TimeLimit *int32 `db:"time_limit"` - MemoryLimit *int32 `db:"memory_limit"` - CreatedAt *time.Time `db:"created_at"` - UpdatedAt *time.Time `db:"updated_at"` -} diff --git a/pkg/models/result.go b/pkg/models/result.go deleted file mode 100644 index d427a6d..0000000 --- a/pkg/models/result.go +++ /dev/null @@ -1,31 +0,0 @@ -package models - -import ( - "errors" - "git.sch9.ru/new_gate/ms-tester/internal/lib" -) - -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 lib.ServiceError(ErrBadResult, lib.ErrValidationFailed, "bad result") -} diff --git a/pkg/models/role.go b/pkg/models/role.go deleted file mode 100644 index a48cca8..0000000 --- a/pkg/models/role.go +++ /dev/null @@ -1,53 +0,0 @@ -package models - -import ( - "errors" - "git.sch9.ru/new_gate/ms-tester/internal/lib" -) - -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 lib.ServiceError(ErrBadRole, lib.ErrValidationFailed, "bad role") -} - -func (role Role) AsPointer() *Role { - return &role -} diff --git a/pkg/models/solution.go b/pkg/models/solution.go deleted file mode 100644 index 9eb54aa..0000000 --- a/pkg/models/solution.go +++ /dev/null @@ -1,14 +0,0 @@ -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"` -} diff --git a/pkg/models/subtask.go b/pkg/models/subtask.go deleted file mode 100644 index d4d51c0..0000000 --- a/pkg/models/subtask.go +++ /dev/null @@ -1,8 +0,0 @@ -package models - -type SubTask struct { - Id *int32 `db:"id"` - ContestId *int32 `db:"contest_id"` - TestgroupId *int32 `db:"testgroup_id"` - TaskId *int32 `db:"task_id"` -} diff --git a/pkg/models/task.go b/pkg/models/task.go deleted file mode 100644 index f5e96a4..0000000 --- a/pkg/models/task.go +++ /dev/null @@ -1,9 +0,0 @@ -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"` -} diff --git a/pkg/models/testgroup.go b/pkg/models/testgroup.go deleted file mode 100644 index f102a0c..0000000 --- a/pkg/models/testgroup.go +++ /dev/null @@ -1,34 +0,0 @@ -package models - -import ( - "errors" - "git.sch9.ru/new_gate/ms-tester/internal/lib" -) - -type TestingStrategy int32 - -const ( - EachTestTS TestingStrategy = 1 - CompleteGroupTS TestingStrategy = 2 -) - -type Testgroup struct { - Id *int32 `db:"id"` - ProblemId *int32 `db:"problem_id"` - TestingStrategy *TestingStrategy `db:"testing_strategy"` -} - -type TestGroupData struct { - Ts TestingStrategy - TestAmount int32 -} - -var ErrBadTestingStrategy = errors.New("bad testing strategy") - -func (ts TestingStrategy) Valid() error { - switch ts { - case EachTestTS, CompleteGroupTS: - return nil - } - return lib.ServiceError(ErrBadTestingStrategy, lib.ErrValidationFailed, "bad testing strategy") -} diff --git a/pkg/models/user.go b/pkg/models/user.go deleted file mode 100644 index 357600c..0000000 --- a/pkg/models/user.go +++ /dev/null @@ -1,9 +0,0 @@ -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"` -}