diff --git a/internal/models/language.go b/internal/models/language.go deleted file mode 100644 index 324b3af..0000000 --- a/internal/models/language.go +++ /dev/null @@ -1,13 +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/internal/models/result.go b/internal/models/result.go deleted file mode 100644 index ef413b4..0000000 --- a/internal/models/result.go +++ /dev/null @@ -1,26 +0,0 @@ -package models - -//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 -//} diff --git a/internal/models/solution.go b/internal/models/solution.go index 46e1c8d..b20dcd1 100644 --- a/internal/models/solution.go +++ b/internal/models/solution.go @@ -48,3 +48,40 @@ type SolutionsFilter struct { State *int32 Order *int32 } + +//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 +//} +// +//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/internal/models/task.go b/internal/models/task.go index 2f40ed4..04e2c55 100644 --- a/internal/models/task.go +++ b/internal/models/task.go @@ -22,7 +22,7 @@ type Task struct { UpdatedAt time.Time `db:"updated_at"` } -type RichTask struct { +type TasksListItem struct { Id int32 `db:"id"` ProblemId int32 `db:"problem_id"` ContestId int32 `db:"contest_id"` diff --git a/internal/tester/delivery/rest/handlers.go b/internal/tester/delivery/rest/handlers.go index 29c9cea..438192b 100644 --- a/internal/tester/delivery/rest/handlers.go +++ b/internal/tester/delivery/rest/handlers.go @@ -125,18 +125,18 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error { UpdatedAt: contest.UpdatedAt, }, Tasks: make([]struct { - BestSolution testerv1.BestSolution `json:"best_solution"` - Task testerv1.RichTask `json:"task"` - }, len(tasks)), + Solution testerv1.Solution `json:"solution"` + Task testerv1.TasksListItem `json:"task"` + }, 0), } for i, task := range tasks { resp.Tasks[i] = struct { - BestSolution testerv1.BestSolution `json:"best_solution"` - Task testerv1.RichTask `json:"task"` + Solution testerv1.Solution `json:"solution"` + Task testerv1.TasksListItem `json:"task"` }{ - BestSolution: testerv1.BestSolution{}, - Task: testerv1.RichTask{ + Solution: testerv1.Solution{}, + Task: testerv1.TasksListItem{ Id: task.Id, ProblemId: task.ProblemId, Position: task.Position, @@ -350,7 +350,7 @@ func (h *TesterHandlers) ListSolutions(c *fiber.Ctx, params testerv1.ListSolutio } resp := testerv1.ListSolutionsResponse{ - Solutions: make([]testerv1.SolutionListItem, len(list)), + Solutions: make([]testerv1.SolutionsListItem, len(list)), Page: params.Page, MaxPage: func() int32 { if total%params.PageSize == 0 { @@ -361,7 +361,7 @@ func (h *TesterHandlers) ListSolutions(c *fiber.Ctx, params testerv1.ListSolutio } for i, solution := range list { - resp.Solutions[i] = testerv1.SolutionListItem{ + resp.Solutions[i] = testerv1.SolutionsListItem{ Id: solution.Id, TaskId: solution.TaskId, ContestId: solution.ContestId, @@ -461,13 +461,13 @@ func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error { resp := testerv1.GetTaskResponse{ Contest: struct { - Id int32 `json:"id"` - Tasks []testerv1.RichTask `json:"tasks"` - Title string `json:"title"` + Id int32 `json:"id"` + Tasks []testerv1.TasksListItem `json:"tasks"` + Title string `json:"title"` }{ Id: contest.Id, Title: contest.Title, - Tasks: make([]testerv1.RichTask, len(tasks)), + Tasks: make([]testerv1.TasksListItem, len(tasks)), }, Task: testerv1.Task{ Id: t.Id, @@ -488,7 +488,7 @@ func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error { } for i, task := range tasks { - resp.Contest.Tasks[i] = testerv1.RichTask{ + resp.Contest.Tasks[i] = testerv1.TasksListItem{ Id: task.Id, Position: task.Position, Title: task.Title, @@ -520,20 +520,20 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara resp := testerv1.GetMonitorResponse{ Contest: struct { - Id int32 `json:"id"` - Tasks []testerv1.RichTask `json:"tasks"` - Title string `json:"title"` + Id int32 `json:"id"` + Tasks []testerv1.TasksListItem `json:"tasks"` + Title string `json:"title"` }{ Id: contest.Id, Title: contest.Title, - Tasks: make([]testerv1.RichTask, len(tasks)), + Tasks: make([]testerv1.TasksListItem, len(tasks)), }, Participants: make([]struct { - Id int32 `json:"id"` - Name string `json:"name"` - PenaltyInTotal int32 `json:"penalty_in_total"` - Solutions []testerv1.SolutionListItem `json:"solutions"` - SolvedInTotal int32 `json:"solved_in_total"` + Id int32 `json:"id"` + Name string `json:"name"` + PenaltyInTotal int32 `json:"penalty_in_total"` + Solutions []testerv1.SolutionsListItem `json:"solutions"` + SolvedInTotal int32 `json:"solved_in_total"` }, len(monitor.Participants)), SummaryPerProblem: make([]struct { Id int32 `json:"id"` @@ -544,21 +544,21 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara for i, participant := range monitor.Participants { resp.Participants[i] = struct { - Id int32 `json:"id"` - Name string `json:"name"` - PenaltyInTotal int32 `json:"penalty_in_total"` - Solutions []testerv1.SolutionListItem `json:"solutions"` - SolvedInTotal int32 `json:"solved_in_total"` + Id int32 `json:"id"` + Name string `json:"name"` + PenaltyInTotal int32 `json:"penalty_in_total"` + Solutions []testerv1.SolutionsListItem `json:"solutions"` + SolvedInTotal int32 `json:"solved_in_total"` }{ Id: participant.Id, Name: participant.Name, PenaltyInTotal: participant.PenaltyInTotal, - Solutions: make([]testerv1.SolutionListItem, len(participant.Solutions)), + Solutions: make([]testerv1.SolutionsListItem, len(participant.Solutions)), SolvedInTotal: participant.SolvedInTotal, } for j, solution := range participant.Solutions { - resp.Participants[i].Solutions[j] = testerv1.SolutionListItem{ + resp.Participants[i].Solutions[j] = testerv1.SolutionsListItem{ ContestId: solution.ContestId, CreatedAt: solution.CreatedAt, Id: solution.Id, @@ -587,7 +587,7 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara } for i, task := range tasks { - resp.Contest.Tasks[i] = testerv1.RichTask{ + resp.Contest.Tasks[i] = testerv1.TasksListItem{ Id: task.Id, Position: task.Position, Title: task.Title, diff --git a/internal/tester/pg_repository.go b/internal/tester/pg_repository.go index b559614..d71d9fe 100644 --- a/internal/tester/pg_repository.go +++ b/internal/tester/pg_repository.go @@ -39,7 +39,7 @@ type ContestRepository interface { DeleteTask(ctx context.Context, taskId int32) error AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error) DeleteParticipant(ctx context.Context, participantId int32) error - ReadRichTasks(ctx context.Context, contestId int32) ([]*models.RichTask, error) + ReadRichTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error) ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error diff --git a/internal/tester/repository/pg_contests_repository.go b/internal/tester/repository/pg_contests_repository.go index 9e8e739..ba3b0f8 100644 --- a/internal/tester/repository/pg_contests_repository.go +++ b/internal/tester/repository/pg_contests_repository.go @@ -152,10 +152,10 @@ FROM tasks INNER JOIN problems ON tasks.problem_id = problems.id WHERE contest_id = ? ORDER BY position` -func (r *ContestRepository) ReadRichTasks(ctx context.Context, contestId int32) ([]*models.RichTask, error) { +func (r *ContestRepository) ReadRichTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) { const op = "ContestRepository.ReadTasks" - var tasks []*models.RichTask + var tasks []*models.TasksListItem query := r.db.Rebind(readTasksQuery) err := r.db.SelectContext(ctx, &tasks, query, contestId) if err != nil { diff --git a/internal/tester/usecase.go b/internal/tester/usecase.go index dede5b2..1d970d1 100644 --- a/internal/tester/usecase.go +++ b/internal/tester/usecase.go @@ -21,7 +21,7 @@ type ContestUseCase interface { DeleteTask(ctx context.Context, taskId int32) error AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error) DeleteParticipant(ctx context.Context, participantId int32) error - ReadRichTasks(ctx context.Context, contestId int32) ([]*models.RichTask, error) + ReadRichTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error) ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error diff --git a/internal/tester/usecase/contests_usecase.go b/internal/tester/usecase/contests_usecase.go index 5c23189..af9bcd9 100644 --- a/internal/tester/usecase/contests_usecase.go +++ b/internal/tester/usecase/contests_usecase.go @@ -46,7 +46,7 @@ func (uc *ContestUseCase) DeleteParticipant(ctx context.Context, participantId i return uc.contestRepo.DeleteParticipant(ctx, participantId) } -func (uc *ContestUseCase) ReadRichTasks(ctx context.Context, contestId int32) ([]*models.RichTask, error) { +func (uc *ContestUseCase) ReadRichTasks(ctx context.Context, contestId int32) ([]*models.TasksListItem, error) { return uc.contestRepo.ReadRichTasks(ctx, contestId) }