feat(tester): add UpdateContest endpoint
This commit is contained in:
parent
2bc625363d
commit
e1720e7f82
8 changed files with 45 additions and 1 deletions
|
@ -15,3 +15,7 @@ type ContestsListItem struct {
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at"`
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
UpdatedAt time.Time `db:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ContestUpdate struct {
|
||||||
|
Title *string `json:"title"`
|
||||||
|
}
|
||||||
|
|
|
@ -20,4 +20,5 @@ type Handlers interface {
|
||||||
GetProblem(c *fiber.Ctx, id int32) error
|
GetProblem(c *fiber.Ctx, id int32) error
|
||||||
ListParticipants(c *fiber.Ctx, params testerv1.ListParticipantsParams) error
|
ListParticipants(c *fiber.Ctx, params testerv1.ListParticipantsParams) error
|
||||||
UpdateProblem(c *fiber.Ctx, id int32) error
|
UpdateProblem(c *fiber.Ctx, id int32) error
|
||||||
|
UpdateContest(c *fiber.Ctx, id int32) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,3 +290,20 @@ func (h *TesterHandlers) UpdateProblem(c *fiber.Ctx, id int32) error {
|
||||||
|
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *TesterHandlers) UpdateContest(c *fiber.Ctx, id int32) error {
|
||||||
|
var req testerv1.UpdateContestRequest
|
||||||
|
err := c.BodyParser(&req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.contestsUC.UpdateContest(c.Context(), id, models.ContestUpdate{
|
||||||
|
Title: req.Title,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return c.SendStatus(pkg.ToREST(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.SendStatus(fiber.StatusOK)
|
||||||
|
}
|
||||||
|
|
|
@ -42,4 +42,5 @@ type ContestRepository interface {
|
||||||
ReadRichTasks(ctx context.Context, contestId int32) ([]*models.RichTask, error)
|
ReadRichTasks(ctx context.Context, contestId int32) ([]*models.RichTask, error)
|
||||||
ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error)
|
ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error)
|
||||||
ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error)
|
ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error)
|
||||||
|
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -212,3 +212,19 @@ func (r *ContestRepository) ListParticipants(ctx context.Context, contestId int3
|
||||||
|
|
||||||
return participants, count, nil
|
return participants, count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
updateContestQuery = "UPDATE contests SET title = COALESCE(?, title) WHERE id = ?"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (r *ContestRepository) UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error {
|
||||||
|
const op = "ContestRepository.UpdateContest"
|
||||||
|
|
||||||
|
query := r.db.Rebind(updateContestQuery)
|
||||||
|
_, err := r.db.ExecContext(ctx, query, contestUpdate.Title, id)
|
||||||
|
if err != nil {
|
||||||
|
return handlePgErr(err, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -24,4 +24,5 @@ type ContestUseCase interface {
|
||||||
ReadRichTasks(ctx context.Context, contestId int32) ([]*models.RichTask, error)
|
ReadRichTasks(ctx context.Context, contestId int32) ([]*models.RichTask, error)
|
||||||
ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error)
|
ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error)
|
||||||
ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error)
|
ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error)
|
||||||
|
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,3 +57,7 @@ func (uc *ContestUseCase) ListContests(ctx context.Context, page int32, pageSize
|
||||||
func (uc *ContestUseCase) ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) {
|
func (uc *ContestUseCase) ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) {
|
||||||
return uc.contestRepo.ListParticipants(ctx, contestId, page, pageSize)
|
return uc.contestRepo.ListParticipants(ctx, contestId, page, pageSize)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (uc *ContestUseCase) UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error {
|
||||||
|
return uc.contestRepo.UpdateContest(ctx, id, contestUpdate)
|
||||||
|
}
|
||||||
|
|
2
proto
2
proto
|
@ -1 +1 @@
|
||||||
Subproject commit e5f7902c188a6b3daae9b147f687c4564cbfdfba
|
Subproject commit 9be6a6ca9859e44d4b4502b89c071bc8587491b6
|
Loading…
Add table
Reference in a new issue