Skip to content

Commit 7ba8b6b

Browse files
committed
no testcases found error
1 parent 5842331 commit 7ba8b6b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ services:
2626
- postgres
2727
- redis
2828

29+
nginx:
30+
image: nginx:latest
31+
ports:
32+
- "80:80" # Replace 8080 with the desired port for your application
33+
- "443:443"
34+
volumes:
35+
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf # Mount your Nginx configuration file
36+
depends_on:
37+
- api # Nginx depends on the API service being available
38+
39+
2940
volumes:
3041
postgres_data:
3142
driver: local

internal/controllers/submission.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controllers
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"io"
78
"net/http"
@@ -70,6 +71,14 @@ func SubmitCode(w http.ResponseWriter, r *http.Request) {
7071

7172
payload, testcase_id, err := submission.CreateSubmission(ctx, question_id, req.LanguageID, req.SourceCode)
7273
if err != nil {
74+
if errors.Is(err, submission.ErrNoTestCases) {
75+
httphelpers.WriteError(
76+
w,
77+
http.StatusNotFound,
78+
err.Error(),
79+
)
80+
return
81+
}
7382
httphelpers.WriteError(
7483
w,
7584
http.StatusInternalServerError,

internal/helpers/submission/submission.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type Token struct {
1818
Token string `json:"token"`
1919
}
2020

21+
var ErrNoTestCases = fmt.Errorf("no testcases present for question_id")
22+
2123
type Payload struct {
2224
Submissions []Submission `json:"submissions"`
2325
}
@@ -40,6 +42,11 @@ func CreateSubmission(
4042
}
4143
return nil, nil, fmt.Errorf("error getting test cases for question_id %d: %v", question_id, err)
4244
}
45+
46+
if len(testcases) == 0 {
47+
return nil, nil, ErrNoTestCases
48+
}
49+
4350
payload := Payload{
4451
Submissions: make([]Submission, len(testcases)),
4552
}

0 commit comments

Comments
 (0)