aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/db/query.sql.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-08 03:57:16 +0900
committernsfisis <nsfisis@gmail.com>2024-08-08 04:02:37 +0900
commita062af23b2e72c38b667e969652aefcf2238dc1b (patch)
treecbcaa732e083d9465e11396ffc555ba08e0f87ef /backend/db/query.sql.go
parent4eb7e89d6a77a4434bd087fbb86873521d30a8f5 (diff)
downloadphperkaigi-2025-albatross-a062af23b2e72c38b667e969652aefcf2238dc1b.tar.gz
phperkaigi-2025-albatross-a062af23b2e72c38b667e969652aefcf2238dc1b.tar.zst
phperkaigi-2025-albatross-a062af23b2e72c38b667e969652aefcf2238dc1b.zip
feat(backend): aggregate testcase results
Diffstat (limited to 'backend/db/query.sql.go')
-rw-r--r--backend/db/query.sql.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go
index cfb97fd..5475067 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -11,6 +11,28 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
+const aggregateTestcaseResults = `-- name: AggregateTestcaseResults :one
+SELECT
+ CASE
+ WHEN COUNT(CASE WHEN r.status IS NULL THEN 1 END) > 0 THEN 'running'
+ WHEN COUNT(CASE WHEN r.status = 'internal_error' THEN 1 END) > 0 THEN 'internal_error'
+ WHEN COUNT(CASE WHEN r.status = 'timeout' THEN 1 END) > 0 THEN 'timeout'
+ WHEN COUNT(CASE WHEN r.status = 'runtime_error' THEN 1 END) > 0 THEN 'runtime_error'
+ WHEN COUNT(CASE WHEN r.status = 'wrong_answer' THEN 1 END) > 0 THEN 'wrong_answer'
+ ELSE 'success'
+ END AS status
+FROM testcases
+LEFT JOIN testcase_results AS r ON testcases.testcase_id = r.testcase_id
+WHERE r.submission_id = $1
+`
+
+func (q *Queries) AggregateTestcaseResults(ctx context.Context, submissionID int32) (string, error) {
+ row := q.db.QueryRow(ctx, aggregateTestcaseResults, submissionID)
+ var status string
+ err := row.Scan(&status)
+ return status, err
+}
+
const createSubmission = `-- name: CreateSubmission :one
INSERT INTO submissions (game_id, user_id, code, code_size)
VALUES ($1, $2, $3, $4)