feat(tester): extend ListContests endpoint
This commit is contained in:
parent
251772a049
commit
52d38d07bb
8 changed files with 66 additions and 4 deletions
|
@ -19,8 +19,33 @@ func NewTesterHandlers(problemsUC tester.ProblemUseCase, contestsUC tester.Conte
|
|||
}
|
||||
}
|
||||
|
||||
func (h *TesterHandlers) ListContests(c *fiber.Ctx) error {
|
||||
return c.SendStatus(fiber.StatusNotImplemented)
|
||||
func (h *TesterHandlers) ListContests(c *fiber.Ctx, params testerv1.ListContestsParams) error {
|
||||
contests, count, err := h.contestsUC.ListContests(c.Context(), params.Page, params.PageSize)
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
resp := testerv1.ListContestsResponse{
|
||||
Contests: make([]testerv1.ContestsListItem, len(contests)),
|
||||
Page: params.Page,
|
||||
MaxPage: func() int32 {
|
||||
if count%params.PageSize == 0 {
|
||||
return count / params.PageSize
|
||||
}
|
||||
return count/params.PageSize + 1
|
||||
}(),
|
||||
}
|
||||
|
||||
for i, contest := range contests {
|
||||
resp.Contests[i] = testerv1.ContestsListItem{
|
||||
Id: contest.Id,
|
||||
Title: contest.Title,
|
||||
CreatedAt: contest.CreatedAt,
|
||||
UpdatedAt: contest.UpdatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
return c.JSON(resp)
|
||||
}
|
||||
|
||||
func (h *TesterHandlers) ListProblems(c *fiber.Ctx, params testerv1.ListProblemsParams) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue