feat(tester):
This commit is contained in:
parent
52d38d07bb
commit
50a4f87f53
9 changed files with 104 additions and 22 deletions
|
@ -174,11 +174,41 @@ func (r *ContestRepository) ListContests(ctx context.Context, page int32, pageSi
|
|||
return nil, 0, handlePgErr(err, op)
|
||||
}
|
||||
|
||||
query = r.db.Rebind(countContestsQuery)
|
||||
var count int32
|
||||
err = r.db.GetContext(ctx, &count, countContestsQuery)
|
||||
err = r.db.GetContext(ctx, &count, query)
|
||||
if err != nil {
|
||||
return nil, 0, handlePgErr(err, op)
|
||||
}
|
||||
|
||||
return tasks, count, nil
|
||||
}
|
||||
|
||||
const (
|
||||
readParticipantsListQuery = `SELECT id, user_id, name, created_at, updated_at FROM participants WHERE contest_id = ? LIMIT ? OFFSET ?`
|
||||
countParticipantsQuery = "SELECT COUNT(*) FROM participants WHERE contest_id = ?"
|
||||
)
|
||||
|
||||
func (r *ContestRepository) ListParticipants(ctx context.Context, contestId int32, page int32, pageSize int32) ([]*models.ParticipantsListItem, int32, error) {
|
||||
const op = "ContestRepository.ReadParticipants"
|
||||
|
||||
if pageSize > 20 {
|
||||
pageSize = 1
|
||||
}
|
||||
|
||||
var participants []*models.ParticipantsListItem
|
||||
query := r.db.Rebind(readParticipantsListQuery)
|
||||
err := r.db.SelectContext(ctx, &participants, query, contestId, pageSize, (page-1)*pageSize)
|
||||
if err != nil {
|
||||
return nil, 0, handlePgErr(err, op)
|
||||
}
|
||||
|
||||
query = r.db.Rebind(countParticipantsQuery)
|
||||
var count int32
|
||||
err = r.db.GetContext(ctx, &count, query, contestId)
|
||||
if err != nil {
|
||||
return nil, 0, handlePgErr(err, op)
|
||||
}
|
||||
|
||||
return participants, count, nil
|
||||
}
|
||||
|
|
|
@ -89,8 +89,10 @@ func (r *ProblemRepository) ListProblems(ctx context.Context, page int32, pageSi
|
|||
return nil, 0, handlePgErr(err, op)
|
||||
}
|
||||
|
||||
query = r.db.Rebind(CountProblemsQuery)
|
||||
|
||||
var count int32
|
||||
err = r.db.GetContext(ctx, &count, CountProblemsQuery)
|
||||
err = r.db.GetContext(ctx, &count, query)
|
||||
if err != nil {
|
||||
return nil, 0, handlePgErr(err, op)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue