feat(tester):

This commit is contained in:
Vyacheslav1557 2025-03-02 15:45:59 +05:00
parent 52d38d07bb
commit 50a4f87f53
9 changed files with 104 additions and 22 deletions

View file

@ -150,7 +150,7 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error {
return c.JSON(resp)
}
func (h *TesterHandlers) DeleteParticipant(c *fiber.Ctx, id int32, params testerv1.DeleteParticipantParams) error {
func (h *TesterHandlers) DeleteParticipant(c *fiber.Ctx, params testerv1.DeleteParticipantParams) error {
err := h.contestsUC.DeleteParticipant(c.Context(), params.ParticipantId)
if err != nil {
return c.SendStatus(pkg.ToREST(err))
@ -159,8 +159,8 @@ func (h *TesterHandlers) DeleteParticipant(c *fiber.Ctx, id int32, params tester
return c.SendStatus(fiber.StatusOK)
}
func (h *TesterHandlers) AddParticipant(c *fiber.Ctx, id int32, params testerv1.AddParticipantParams) error {
id, err := h.contestsUC.AddParticipant(c.Context(), id, params.UserId)
func (h *TesterHandlers) AddParticipant(c *fiber.Ctx, params testerv1.AddParticipantParams) error {
id, err := h.contestsUC.AddParticipant(c.Context(), params.ContestId, params.UserId)
if err != nil {
return c.SendStatus(pkg.ToREST(err))
}
@ -170,7 +170,7 @@ func (h *TesterHandlers) AddParticipant(c *fiber.Ctx, id int32, params testerv1.
})
}
func (h *TesterHandlers) DeleteTask(c *fiber.Ctx, id int32, params testerv1.DeleteTaskParams) error {
func (h *TesterHandlers) DeleteTask(c *fiber.Ctx, params testerv1.DeleteTaskParams) error {
err := h.contestsUC.DeleteTask(c.Context(), params.TaskId)
if err != nil {
return c.SendStatus(pkg.ToREST(err))
@ -179,13 +179,15 @@ func (h *TesterHandlers) DeleteTask(c *fiber.Ctx, id int32, params testerv1.Dele
return c.SendStatus(fiber.StatusOK)
}
func (h *TesterHandlers) AddTask(c *fiber.Ctx, id int32, params testerv1.AddTaskParams) error {
id, err := h.contestsUC.AddTask(c.Context(), id, params.ProblemId)
func (h *TesterHandlers) AddTask(c *fiber.Ctx, params testerv1.AddTaskParams) error {
id, err := h.contestsUC.AddTask(c.Context(), params.ContestId, params.ProblemId)
if err != nil {
return c.SendStatus(pkg.ToREST(err))
}
return c.SendStatus(fiber.StatusNotImplemented)
return c.JSON(testerv1.AddTaskResponse{
Id: id,
})
}
func (h *TesterHandlers) CreateProblem(c *fiber.Ctx) error {
@ -231,3 +233,33 @@ func (h *TesterHandlers) GetProblem(c *fiber.Ctx, id int32) error {
}},
)
}
func (h *TesterHandlers) ListParticipants(c *fiber.Ctx, params testerv1.ListParticipantsParams) error {
participants, count, err := h.contestsUC.ListParticipants(c.Context(), params.ContestId, params.Page, params.PageSize)
if err != nil {
return c.SendStatus(pkg.ToREST(err))
}
resp := testerv1.ListParticipantsResponse{
Participants: make([]testerv1.ParticipantsListItem, len(participants)),
Page: params.Page,
MaxPage: func() int32 {
if count%params.PageSize == 0 {
return count / params.PageSize
}
return count/params.PageSize + 1
}(),
}
for i, participant := range participants {
resp.Participants[i] = testerv1.ParticipantsListItem{
Id: participant.Id,
UserId: participant.UserId,
Name: participant.Name,
CreatedAt: participant.CreatedAt,
UpdatedAt: participant.UpdatedAt,
}
}
return c.JSON(resp)
}