refactor(user,session): refactor api
This commit is contained in:
parent
b960a923d2
commit
f89e89faae
9 changed files with 74 additions and 76 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue