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:
OXYgen 2025-04-02 17:45:09 +00:00
commit 2ab7a16ddf
3 changed files with 17 additions and 3 deletions

View file

@ -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"
)