refactor(user,session): refactor api
This commit is contained in:
parent
b960a923d2
commit
f89e89faae
9 changed files with 74 additions and 76 deletions
|
@ -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"}},
|
|
||||||
//}
|
|
|
@ -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
|
|
||||||
//}
|
|
|
@ -48,3 +48,40 @@ type SolutionsFilter struct {
|
||||||
State *int32
|
State *int32
|
||||||
Order *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"}},
|
||||||
|
//}
|
||||||
|
|
|
@ -22,7 +22,7 @@ type Task struct {
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
UpdatedAt time.Time `db:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RichTask struct {
|
type TasksListItem struct {
|
||||||
Id int32 `db:"id"`
|
Id int32 `db:"id"`
|
||||||
ProblemId int32 `db:"problem_id"`
|
ProblemId int32 `db:"problem_id"`
|
||||||
ContestId int32 `db:"contest_id"`
|
ContestId int32 `db:"contest_id"`
|
||||||
|
|
|
@ -125,18 +125,18 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error {
|
||||||
UpdatedAt: contest.UpdatedAt,
|
UpdatedAt: contest.UpdatedAt,
|
||||||
},
|
},
|
||||||
Tasks: make([]struct {
|
Tasks: make([]struct {
|
||||||
BestSolution testerv1.BestSolution `json:"best_solution"`
|
Solution testerv1.Solution `json:"solution"`
|
||||||
Task testerv1.RichTask `json:"task"`
|
Task testerv1.TasksListItem `json:"task"`
|
||||||
}, len(tasks)),
|
}, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, task := range tasks {
|
for i, task := range tasks {
|
||||||
resp.Tasks[i] = struct {
|
resp.Tasks[i] = struct {
|
||||||
BestSolution testerv1.BestSolution `json:"best_solution"`
|
Solution testerv1.Solution `json:"solution"`
|
||||||
Task testerv1.RichTask `json:"task"`
|
Task testerv1.TasksListItem `json:"task"`
|
||||||
}{
|
}{
|
||||||
BestSolution: testerv1.BestSolution{},
|
Solution: testerv1.Solution{},
|
||||||
Task: testerv1.RichTask{
|
Task: testerv1.TasksListItem{
|
||||||
Id: task.Id,
|
Id: task.Id,
|
||||||
ProblemId: task.ProblemId,
|
ProblemId: task.ProblemId,
|
||||||
Position: task.Position,
|
Position: task.Position,
|
||||||
|
@ -350,7 +350,7 @@ func (h *TesterHandlers) ListSolutions(c *fiber.Ctx, params testerv1.ListSolutio
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := testerv1.ListSolutionsResponse{
|
resp := testerv1.ListSolutionsResponse{
|
||||||
Solutions: make([]testerv1.SolutionListItem, len(list)),
|
Solutions: make([]testerv1.SolutionsListItem, len(list)),
|
||||||
Page: params.Page,
|
Page: params.Page,
|
||||||
MaxPage: func() int32 {
|
MaxPage: func() int32 {
|
||||||
if total%params.PageSize == 0 {
|
if total%params.PageSize == 0 {
|
||||||
|
@ -361,7 +361,7 @@ func (h *TesterHandlers) ListSolutions(c *fiber.Ctx, params testerv1.ListSolutio
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, solution := range list {
|
for i, solution := range list {
|
||||||
resp.Solutions[i] = testerv1.SolutionListItem{
|
resp.Solutions[i] = testerv1.SolutionsListItem{
|
||||||
Id: solution.Id,
|
Id: solution.Id,
|
||||||
TaskId: solution.TaskId,
|
TaskId: solution.TaskId,
|
||||||
ContestId: solution.ContestId,
|
ContestId: solution.ContestId,
|
||||||
|
@ -462,12 +462,12 @@ func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error {
|
||||||
resp := testerv1.GetTaskResponse{
|
resp := testerv1.GetTaskResponse{
|
||||||
Contest: struct {
|
Contest: struct {
|
||||||
Id int32 `json:"id"`
|
Id int32 `json:"id"`
|
||||||
Tasks []testerv1.RichTask `json:"tasks"`
|
Tasks []testerv1.TasksListItem `json:"tasks"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
}{
|
}{
|
||||||
Id: contest.Id,
|
Id: contest.Id,
|
||||||
Title: contest.Title,
|
Title: contest.Title,
|
||||||
Tasks: make([]testerv1.RichTask, len(tasks)),
|
Tasks: make([]testerv1.TasksListItem, len(tasks)),
|
||||||
},
|
},
|
||||||
Task: testerv1.Task{
|
Task: testerv1.Task{
|
||||||
Id: t.Id,
|
Id: t.Id,
|
||||||
|
@ -488,7 +488,7 @@ func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, task := range tasks {
|
for i, task := range tasks {
|
||||||
resp.Contest.Tasks[i] = testerv1.RichTask{
|
resp.Contest.Tasks[i] = testerv1.TasksListItem{
|
||||||
Id: task.Id,
|
Id: task.Id,
|
||||||
Position: task.Position,
|
Position: task.Position,
|
||||||
Title: task.Title,
|
Title: task.Title,
|
||||||
|
@ -521,18 +521,18 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara
|
||||||
resp := testerv1.GetMonitorResponse{
|
resp := testerv1.GetMonitorResponse{
|
||||||
Contest: struct {
|
Contest: struct {
|
||||||
Id int32 `json:"id"`
|
Id int32 `json:"id"`
|
||||||
Tasks []testerv1.RichTask `json:"tasks"`
|
Tasks []testerv1.TasksListItem `json:"tasks"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
}{
|
}{
|
||||||
Id: contest.Id,
|
Id: contest.Id,
|
||||||
Title: contest.Title,
|
Title: contest.Title,
|
||||||
Tasks: make([]testerv1.RichTask, len(tasks)),
|
Tasks: make([]testerv1.TasksListItem, len(tasks)),
|
||||||
},
|
},
|
||||||
Participants: make([]struct {
|
Participants: make([]struct {
|
||||||
Id int32 `json:"id"`
|
Id int32 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PenaltyInTotal int32 `json:"penalty_in_total"`
|
PenaltyInTotal int32 `json:"penalty_in_total"`
|
||||||
Solutions []testerv1.SolutionListItem `json:"solutions"`
|
Solutions []testerv1.SolutionsListItem `json:"solutions"`
|
||||||
SolvedInTotal int32 `json:"solved_in_total"`
|
SolvedInTotal int32 `json:"solved_in_total"`
|
||||||
}, len(monitor.Participants)),
|
}, len(monitor.Participants)),
|
||||||
SummaryPerProblem: make([]struct {
|
SummaryPerProblem: make([]struct {
|
||||||
|
@ -547,18 +547,18 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara
|
||||||
Id int32 `json:"id"`
|
Id int32 `json:"id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PenaltyInTotal int32 `json:"penalty_in_total"`
|
PenaltyInTotal int32 `json:"penalty_in_total"`
|
||||||
Solutions []testerv1.SolutionListItem `json:"solutions"`
|
Solutions []testerv1.SolutionsListItem `json:"solutions"`
|
||||||
SolvedInTotal int32 `json:"solved_in_total"`
|
SolvedInTotal int32 `json:"solved_in_total"`
|
||||||
}{
|
}{
|
||||||
Id: participant.Id,
|
Id: participant.Id,
|
||||||
Name: participant.Name,
|
Name: participant.Name,
|
||||||
PenaltyInTotal: participant.PenaltyInTotal,
|
PenaltyInTotal: participant.PenaltyInTotal,
|
||||||
Solutions: make([]testerv1.SolutionListItem, len(participant.Solutions)),
|
Solutions: make([]testerv1.SolutionsListItem, len(participant.Solutions)),
|
||||||
SolvedInTotal: participant.SolvedInTotal,
|
SolvedInTotal: participant.SolvedInTotal,
|
||||||
}
|
}
|
||||||
|
|
||||||
for j, solution := range participant.Solutions {
|
for j, solution := range participant.Solutions {
|
||||||
resp.Participants[i].Solutions[j] = testerv1.SolutionListItem{
|
resp.Participants[i].Solutions[j] = testerv1.SolutionsListItem{
|
||||||
ContestId: solution.ContestId,
|
ContestId: solution.ContestId,
|
||||||
CreatedAt: solution.CreatedAt,
|
CreatedAt: solution.CreatedAt,
|
||||||
Id: solution.Id,
|
Id: solution.Id,
|
||||||
|
@ -587,7 +587,7 @@ func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorPara
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, task := range tasks {
|
for i, task := range tasks {
|
||||||
resp.Contest.Tasks[i] = testerv1.RichTask{
|
resp.Contest.Tasks[i] = testerv1.TasksListItem{
|
||||||
Id: task.Id,
|
Id: task.Id,
|
||||||
Position: task.Position,
|
Position: task.Position,
|
||||||
Title: task.Title,
|
Title: task.Title,
|
||||||
|
|
|
@ -39,7 +39,7 @@ type ContestRepository interface {
|
||||||
DeleteTask(ctx context.Context, taskId int32) error
|
DeleteTask(ctx context.Context, taskId int32) error
|
||||||
AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error)
|
AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error)
|
||||||
DeleteParticipant(ctx context.Context, participantId 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)
|
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)
|
ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error)
|
||||||
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
|
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
|
||||||
|
|
|
@ -152,10 +152,10 @@ FROM tasks
|
||||||
INNER JOIN problems ON tasks.problem_id = problems.id
|
INNER JOIN problems ON tasks.problem_id = problems.id
|
||||||
WHERE contest_id = ? ORDER BY position`
|
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"
|
const op = "ContestRepository.ReadTasks"
|
||||||
|
|
||||||
var tasks []*models.RichTask
|
var tasks []*models.TasksListItem
|
||||||
query := r.db.Rebind(readTasksQuery)
|
query := r.db.Rebind(readTasksQuery)
|
||||||
err := r.db.SelectContext(ctx, &tasks, query, contestId)
|
err := r.db.SelectContext(ctx, &tasks, query, contestId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -21,7 +21,7 @@ type ContestUseCase interface {
|
||||||
DeleteTask(ctx context.Context, taskId int32) error
|
DeleteTask(ctx context.Context, taskId int32) error
|
||||||
AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error)
|
AddParticipant(ctx context.Context, contestId int32, userId int32) (int32, error)
|
||||||
DeleteParticipant(ctx context.Context, participantId 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)
|
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)
|
ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error)
|
||||||
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
|
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
|
||||||
|
|
|
@ -46,7 +46,7 @@ func (uc *ContestUseCase) DeleteParticipant(ctx context.Context, participantId i
|
||||||
return uc.contestRepo.DeleteParticipant(ctx, participantId)
|
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)
|
return uc.contestRepo.ReadRichTasks(ctx, contestId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue