Merge pull request 'Added solved_count to listproblems endpoint' (#2) from listproblems-solved-count into develop
Reviewed-on: #2 Reviewed-by: Vyacheslav Birin <vyacheslav1557@noreply.localhost> Reviewed-by: Holoti <holoti@noreply.localhost>
This commit is contained in:
commit
2ab7a16ddf
3 changed files with 17 additions and 3 deletions
|
@ -32,6 +32,7 @@ type ProblemsListItem struct {
|
|||
TimeLimit int32 `db:"time_limit"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
SolvedCount int32 `db:"solved_count"`
|
||||
}
|
||||
|
||||
type ProblemsList struct {
|
||||
|
|
|
@ -467,6 +467,7 @@ func PLI2PLI(p models.ProblemsListItem) testerv1.ProblemsListItem {
|
|||
TimeLimit: p.TimeLimit,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
SolvedCount: p.SolvedCount,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,9 +82,21 @@ func (r *ProblemRepository) DeleteProblem(ctx context.Context, q tester.Querier,
|
|||
}
|
||||
|
||||
const (
|
||||
ListProblemsQuery = `SELECT id, title, time_limit, memory_limit, created_at, updated_at
|
||||
FROM problems
|
||||
LIMIT ? OFFSET ?`
|
||||
ListProblemsQuery = `
|
||||
SELECT
|
||||
p.id,p.title,p.memory_limit,p.time_limit,p.created_at,p.updated_at,
|
||||
COALESCE(solved_count, 0) AS solved_count
|
||||
FROM problems p
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
t.problem_id,
|
||||
COUNT(DISTINCT s.participant_id) AS solved_count
|
||||
FROM solutions s
|
||||
JOIN tasks t ON s.task_id = t.id
|
||||
WHERE s.state = 5
|
||||
GROUP BY t.problem_id
|
||||
) sol ON p.id = sol.problem_id
|
||||
LIMIT ? OFFSET ?`
|
||||
CountProblemsQuery = "SELECT COUNT(*) FROM problems"
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue