feat(tester): extend ListContests endpoint

This commit is contained in:
Vyacheslav1557 2025-03-02 14:13:58 +05:00
parent 251772a049
commit 52d38d07bb
8 changed files with 66 additions and 4 deletions

View file

@ -158,3 +158,27 @@ func (r *ContestRepository) ReadRichTasks(ctx context.Context, contestId int32)
}
return tasks, nil
}
const (
readContestsListQuery = `SELECT id, title, created_at, updated_at FROM contests LIMIT ? OFFSET ?`
countContestsQuery = "SELECT COUNT(*) FROM contests"
)
func (r *ContestRepository) ListContests(ctx context.Context, page int32, pageSize int32) ([]*models.ContestsListItem, int32, error) {
const op = "ContestRepository.ReadTasks"
var tasks []*models.ContestsListItem
query := r.db.Rebind(readContestsListQuery)
err := r.db.SelectContext(ctx, &tasks, query, pageSize, (page-1)*pageSize)
if err != nil {
return nil, 0, handlePgErr(err, op)
}
var count int32
err = r.db.GetContext(ctx, &count, countContestsQuery)
if err != nil {
return nil, 0, handlePgErr(err, op)
}
return tasks, count, nil
}