feat(tester): add endpoints
add GetMonitor&GetTask endpoints
This commit is contained in:
parent
ef696d2836
commit
b960a923d2
9 changed files with 400 additions and 16 deletions
|
@ -14,7 +14,7 @@ type TesterHandlers struct {
|
|||
contestsUC tester.ContestUseCase
|
||||
}
|
||||
|
||||
func NewTesterHandlers(problemsUC tester.ProblemUseCase, contestsUC tester.ContestRepository) *TesterHandlers {
|
||||
func NewTesterHandlers(problemsUC tester.ProblemUseCase, contestsUC tester.ContestUseCase) *TesterHandlers {
|
||||
return &TesterHandlers{
|
||||
problemsUC: problemsUC,
|
||||
contestsUC: contestsUC,
|
||||
|
@ -120,9 +120,9 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error {
|
|||
resp := testerv1.GetContestResponse{
|
||||
Contest: testerv1.Contest{
|
||||
Id: id,
|
||||
Title: *contest.Title,
|
||||
CreatedAt: *contest.CreatedAt,
|
||||
UpdatedAt: *contest.UpdatedAt,
|
||||
Title: contest.Title,
|
||||
CreatedAt: contest.CreatedAt,
|
||||
UpdatedAt: contest.UpdatedAt,
|
||||
},
|
||||
Tasks: make([]struct {
|
||||
BestSolution testerv1.BestSolution `json:"best_solution"`
|
||||
|
@ -172,8 +172,8 @@ func (h *TesterHandlers) AddParticipant(c *fiber.Ctx, params testerv1.AddPartici
|
|||
})
|
||||
}
|
||||
|
||||
func (h *TesterHandlers) DeleteTask(c *fiber.Ctx, params testerv1.DeleteTaskParams) error {
|
||||
err := h.contestsUC.DeleteTask(c.Context(), params.TaskId)
|
||||
func (h *TesterHandlers) DeleteTask(c *fiber.Ctx, id int32) error {
|
||||
err := h.contestsUC.DeleteTask(c.Context(), id)
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
@ -442,3 +442,161 @@ func (h *TesterHandlers) GetSolution(c *fiber.Ctx, id int32) error {
|
|||
}},
|
||||
)
|
||||
}
|
||||
|
||||
func (h *TesterHandlers) GetTask(c *fiber.Ctx, id int32) error {
|
||||
contest, err := h.contestsUC.ReadContestById(c.Context(), id)
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
tasks, err := h.contestsUC.ReadRichTasks(c.Context(), id)
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
t, err := h.contestsUC.ReadTask(c.Context(), id)
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
resp := testerv1.GetTaskResponse{
|
||||
Contest: struct {
|
||||
Id int32 `json:"id"`
|
||||
Tasks []testerv1.RichTask `json:"tasks"`
|
||||
Title string `json:"title"`
|
||||
}{
|
||||
Id: contest.Id,
|
||||
Title: contest.Title,
|
||||
Tasks: make([]testerv1.RichTask, len(tasks)),
|
||||
},
|
||||
Task: testerv1.Task{
|
||||
Id: t.Id,
|
||||
Title: t.Title,
|
||||
MemoryLimit: t.MemoryLimit,
|
||||
TimeLimit: t.TimeLimit,
|
||||
|
||||
InputFormatHtml: t.InputFormatHtml,
|
||||
LegendHtml: t.LegendHtml,
|
||||
NotesHtml: t.NotesHtml,
|
||||
OutputFormatHtml: t.OutputFormatHtml,
|
||||
Position: t.Position,
|
||||
ScoringHtml: t.ScoringHtml,
|
||||
|
||||
CreatedAt: t.CreatedAt,
|
||||
UpdatedAt: t.UpdatedAt,
|
||||
},
|
||||
}
|
||||
|
||||
for i, task := range tasks {
|
||||
resp.Contest.Tasks[i] = testerv1.RichTask{
|
||||
Id: task.Id,
|
||||
Position: task.Position,
|
||||
Title: task.Title,
|
||||
MemoryLimit: task.MemoryLimit,
|
||||
ProblemId: task.ProblemId,
|
||||
TimeLimit: task.TimeLimit,
|
||||
CreatedAt: task.CreatedAt,
|
||||
UpdatedAt: task.UpdatedAt}
|
||||
}
|
||||
|
||||
return c.JSON(resp)
|
||||
}
|
||||
|
||||
func (h *TesterHandlers) GetMonitor(c *fiber.Ctx, params testerv1.GetMonitorParams) error {
|
||||
contest, err := h.contestsUC.ReadContestById(c.Context(), params.ContestId)
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
monitor, err := h.contestsUC.ReadMonitor(c.Context(), params.ContestId)
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
tasks, err := h.contestsUC.ReadRichTasks(c.Context(), params.ContestId)
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
resp := testerv1.GetMonitorResponse{
|
||||
Contest: struct {
|
||||
Id int32 `json:"id"`
|
||||
Tasks []testerv1.RichTask `json:"tasks"`
|
||||
Title string `json:"title"`
|
||||
}{
|
||||
Id: contest.Id,
|
||||
Title: contest.Title,
|
||||
Tasks: make([]testerv1.RichTask, 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"`
|
||||
}, len(monitor.Participants)),
|
||||
SummaryPerProblem: make([]struct {
|
||||
Id int32 `json:"id"`
|
||||
Success int32 `json:"success"`
|
||||
Total int32 `json:"total"`
|
||||
}, len(monitor.Summary)),
|
||||
}
|
||||
|
||||
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: participant.Id,
|
||||
Name: participant.Name,
|
||||
PenaltyInTotal: participant.PenaltyInTotal,
|
||||
Solutions: make([]testerv1.SolutionListItem, len(participant.Solutions)),
|
||||
SolvedInTotal: participant.SolvedInTotal,
|
||||
}
|
||||
|
||||
for j, solution := range participant.Solutions {
|
||||
resp.Participants[i].Solutions[j] = testerv1.SolutionListItem{
|
||||
ContestId: solution.ContestId,
|
||||
CreatedAt: solution.CreatedAt,
|
||||
Id: solution.Id,
|
||||
Language: solution.Language,
|
||||
ParticipantId: solution.ParticipantId,
|
||||
Penalty: solution.Penalty,
|
||||
Score: solution.Score,
|
||||
State: solution.State,
|
||||
TaskId: solution.TaskId,
|
||||
TotalScore: solution.TotalScore,
|
||||
UpdatedAt: solution.UpdatedAt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i, problem := range monitor.Summary {
|
||||
resp.SummaryPerProblem[i] = struct {
|
||||
Id int32 `json:"id"`
|
||||
Success int32 `json:"success"`
|
||||
Total int32 `json:"total"`
|
||||
}{
|
||||
Id: problem.Id,
|
||||
Success: problem.Success,
|
||||
Total: problem.Total,
|
||||
}
|
||||
}
|
||||
|
||||
for i, task := range tasks {
|
||||
resp.Contest.Tasks[i] = testerv1.RichTask{
|
||||
Id: task.Id,
|
||||
Position: task.Position,
|
||||
Title: task.Title,
|
||||
MemoryLimit: task.MemoryLimit,
|
||||
ProblemId: task.ProblemId,
|
||||
TimeLimit: task.TimeLimit,
|
||||
CreatedAt: task.CreatedAt,
|
||||
UpdatedAt: task.UpdatedAt}
|
||||
}
|
||||
|
||||
return c.JSON(resp)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue