feat(tester): add UpdateParticipant endpoint
This commit is contained in:
parent
e1720e7f82
commit
dd87d63860
8 changed files with 45 additions and 1 deletions
|
@ -19,3 +19,7 @@ type ParticipantsListItem struct {
|
|||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
type ParticipantUpdate struct {
|
||||
Name *string `json:"name"`
|
||||
}
|
||||
|
|
|
@ -21,4 +21,5 @@ type Handlers interface {
|
|||
ListParticipants(c *fiber.Ctx, params testerv1.ListParticipantsParams) error
|
||||
UpdateProblem(c *fiber.Ctx, id int32) error
|
||||
UpdateContest(c *fiber.Ctx, id int32) error
|
||||
UpdateParticipant(c *fiber.Ctx, params testerv1.UpdateParticipantParams) error
|
||||
}
|
||||
|
|
|
@ -307,3 +307,20 @@ func (h *TesterHandlers) UpdateContest(c *fiber.Ctx, id int32) error {
|
|||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
||||
func (h *TesterHandlers) UpdateParticipant(c *fiber.Ctx, params testerv1.UpdateParticipantParams) error {
|
||||
var req testerv1.UpdateParticipantRequest
|
||||
err := c.BodyParser(&req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = h.contestsUC.UpdateParticipant(c.Context(), params.ParticipantId, models.ParticipantUpdate{
|
||||
Name: req.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return c.SendStatus(pkg.ToREST(err))
|
||||
}
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
|
|
@ -43,4 +43,5 @@ type ContestRepository interface {
|
|||
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)
|
||||
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
|
||||
UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error
|
||||
}
|
||||
|
|
|
@ -228,3 +228,19 @@ func (r *ContestRepository) UpdateContest(ctx context.Context, id int32, contest
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
const (
|
||||
updateParticipantQuery = "UPDATE participants SET name = COALESCE(?, name) WHERE id = ?"
|
||||
)
|
||||
|
||||
func (r *ContestRepository) UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error {
|
||||
const op = "ContestRepository.UpdateParticipant"
|
||||
|
||||
query := r.db.Rebind(updateParticipantQuery)
|
||||
_, err := r.db.ExecContext(ctx, query, participantUpdate.Name, id)
|
||||
if err != nil {
|
||||
return handlePgErr(err, op)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -25,4 +25,5 @@ type ContestUseCase interface {
|
|||
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)
|
||||
UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error
|
||||
UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error
|
||||
}
|
||||
|
|
|
@ -61,3 +61,7 @@ func (uc *ContestUseCase) ListParticipants(ctx context.Context, contestId int32,
|
|||
func (uc *ContestUseCase) UpdateContest(ctx context.Context, id int32, contestUpdate models.ContestUpdate) error {
|
||||
return uc.contestRepo.UpdateContest(ctx, id, contestUpdate)
|
||||
}
|
||||
|
||||
func (uc *ContestUseCase) UpdateParticipant(ctx context.Context, id int32, participantUpdate models.ParticipantUpdate) error {
|
||||
return uc.contestRepo.UpdateParticipant(ctx, id, participantUpdate)
|
||||
}
|
||||
|
|
2
proto
2
proto
|
@ -1 +1 @@
|
|||
Subproject commit 9be6a6ca9859e44d4b4502b89c071bc8587491b6
|
||||
Subproject commit d021cf202fde8ba13409b9031d01e8b068b82ca9
|
Loading…
Add table
Reference in a new issue