fix(tester): improve error handling
This commit is contained in:
parent
c67405f584
commit
e6088953b9
14 changed files with 103 additions and 206 deletions
|
@ -2,6 +2,7 @@ package rest
|
|||
|
||||
import (
|
||||
"git.sch9.ru/new_gate/ms-tester/internal/tester"
|
||||
"git.sch9.ru/new_gate/ms-tester/pkg"
|
||||
testerv1 "git.sch9.ru/new_gate/ms-tester/proto/tester/v1"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
@ -29,7 +30,7 @@ func (h *TesterHandlers) ListProblems(c *fiber.Ctx) error {
|
|||
func (h *TesterHandlers) CreateContest(c *fiber.Ctx) error {
|
||||
id, err := h.contestsUC.CreateContest(c.Context(), "Название контеста")
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.JSON(testerv1.CreateContestResponse{
|
||||
|
@ -40,7 +41,7 @@ func (h *TesterHandlers) CreateContest(c *fiber.Ctx) error {
|
|||
func (h *TesterHandlers) DeleteContest(c *fiber.Ctx, id int32) error {
|
||||
err := h.contestsUC.DeleteContest(c.Context(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
|
@ -49,7 +50,7 @@ func (h *TesterHandlers) DeleteContest(c *fiber.Ctx, id int32) error {
|
|||
func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error {
|
||||
contest, err := h.contestsUC.ReadContestById(c.Context(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.JSON(testerv1.GetContestResponse{
|
||||
|
@ -65,7 +66,7 @@ func (h *TesterHandlers) GetContest(c *fiber.Ctx, id int32) error {
|
|||
func (h *TesterHandlers) DeleteParticipant(c *fiber.Ctx, id int32, params testerv1.DeleteParticipantParams) error {
|
||||
err := h.contestsUC.DeleteParticipant(c.Context(), params.ParticipantId)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
|
@ -74,7 +75,7 @@ func (h *TesterHandlers) DeleteParticipant(c *fiber.Ctx, id int32, params tester
|
|||
func (h *TesterHandlers) AddParticipant(c *fiber.Ctx, id int32, params testerv1.AddParticipantParams) error {
|
||||
id, err := h.contestsUC.AddParticipant(c.Context(), id, params.UserId)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.JSON(testerv1.AddParticipantResponse{
|
||||
|
@ -85,7 +86,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 {
|
||||
err := h.contestsUC.DeleteTask(c.Context(), params.TaskId)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
|
@ -94,7 +95,7 @@ func (h *TesterHandlers) DeleteTask(c *fiber.Ctx, id int32, params testerv1.Dele
|
|||
func (h *TesterHandlers) AddTask(c *fiber.Ctx, id int32, params testerv1.AddTaskParams) error {
|
||||
id, err := h.contestsUC.AddTask(c.Context(), id, params.ProblemId)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusNotImplemented)
|
||||
|
@ -103,7 +104,7 @@ func (h *TesterHandlers) AddTask(c *fiber.Ctx, id int32, params testerv1.AddTask
|
|||
func (h *TesterHandlers) CreateProblem(c *fiber.Ctx) error {
|
||||
id, err := h.problemsUC.CreateProblem(c.Context(), "Название задачи")
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.JSON(testerv1.CreateProblemResponse{
|
||||
|
@ -114,7 +115,7 @@ func (h *TesterHandlers) CreateProblem(c *fiber.Ctx) error {
|
|||
func (h *TesterHandlers) DeleteProblem(c *fiber.Ctx, id int32) error {
|
||||
err := h.problemsUC.DeleteProblem(c.Context(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
|
@ -124,7 +125,7 @@ func (h *TesterHandlers) DeleteProblem(c *fiber.Ctx, id int32) error {
|
|||
func (h *TesterHandlers) GetProblem(c *fiber.Ctx, id int32) error {
|
||||
problem, err := h.problemsUC.ReadProblemById(c.Context(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.JSON(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue