Skip to content

Commit c236012

Browse files
authored
Merge pull request #83 from CS3219-AY2425S1/titus/add-ui-for-testcases
feat: update frontend ui for testcases
2 parents 8a31a6f + 1b8eddb commit c236012

File tree

8 files changed

+776
-102
lines changed

8 files changed

+776
-102
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package handlers
2+
3+
import (
4+
"encoding/json"
5+
"execution-service/models"
6+
"execution-service/utils"
7+
"net/http"
8+
9+
"github.com/go-chi/chi/v5"
10+
"google.golang.org/api/iterator"
11+
)
12+
13+
func (s *Service) ReadAllTests(w http.ResponseWriter, r *http.Request) {
14+
ctx := r.Context()
15+
16+
questionDocRefId := chi.URLParam(r, "questionDocRefId")
17+
if questionDocRefId == "" {
18+
http.Error(w, "questionDocRefId is required", http.StatusBadRequest)
19+
return
20+
}
21+
22+
iter := s.Client.Collection("tests").Where("questionDocRefId", "==", questionDocRefId).Limit(1).Documents(ctx)
23+
doc, err := iter.Next()
24+
if err != nil {
25+
if err == iterator.Done {
26+
http.Error(w, "Test not found", http.StatusNotFound)
27+
return
28+
}
29+
http.Error(w, err.Error(), http.StatusInternalServerError)
30+
return
31+
}
32+
defer iter.Stop()
33+
34+
var test models.Test
35+
if err := doc.DataTo(&test); err != nil {
36+
http.Error(w, err.Error(), http.StatusInternalServerError)
37+
return
38+
}
39+
40+
_, hiddenTestCases, err := utils.GetTestLengthAndUnexecutedCases(test.HiddenTestCases)
41+
42+
var hiddenTests []models.HiddenTest
43+
for _, hiddenTestCase := range hiddenTestCases {
44+
hiddenTests = append(hiddenTests, models.HiddenTest{
45+
Input: hiddenTestCase.Input,
46+
Expected: hiddenTestCase.Expected,
47+
})
48+
}
49+
50+
_, visibleTestCases, err := utils.GetTestLengthAndUnexecutedCases(test.VisibleTestCases)
51+
52+
var visibleTests []models.VisibleTest
53+
for _, visibleTestCase := range visibleTestCases {
54+
visibleTests = append(visibleTests, models.VisibleTest{
55+
Input: visibleTestCase.Input,
56+
Expected: visibleTestCase.Expected,
57+
})
58+
}
59+
60+
allTests := models.AllTests{
61+
VisibleTests: visibleTests,
62+
HiddenTests: hiddenTests,
63+
}
64+
65+
w.Header().Set("Content-Type", "application/json")
66+
w.WriteHeader(http.StatusOK)
67+
json.NewEncoder(w).Encode(allTests)
68+
}
69+
70+
//curl -X GET http://localhost:8083/tests/bmzFyLMeSOoYU99pi4yZ/ \
71+
//-H "Content-Type: application/json"
File renamed without changes.

apps/execution-service/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func registerRoutes(r *chi.Mux, service *handlers.Service) {
9393
r.Put("/", service.UpdateTest)
9494
r.Delete("/", service.DeleteTest)
9595
r.Get("/", service.ReadVisibleTests)
96+
r.Get("/readall", service.ReadAllTests)
9697
r.Post("/execute", service.ExecuteVisibleAndCustomTests)
9798
r.Post("/submit", service.ExecuteVisibleAndHiddenTestsAndSubmit)
9899
})

apps/execution-service/models/visibleTest.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ type VisibleTest struct {
44
Input string `json:"input"`
55
Expected string `json:"expected"`
66
}
7+
8+
type HiddenTest struct {
9+
Input string `json:"input"`
10+
Expected string `json:"expected"`
11+
}
12+
13+
type AllTests struct {
14+
VisibleTests []VisibleTest `json:"visibleTests"`
15+
HiddenTests []HiddenTest `json:"hiddenTests"`
16+
}

apps/frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@
3232
"react-use-websocket": "^4.9.0",
3333
"sass": "^1.79.2",
3434
"typeface-montserrat": "^1.1.13",
35+
"uuid": "^11.0.3",
3536
"y-codemirror.next": "^0.3.5",
3637
"y-webrtc": "^10.3.0",
3738
"yjs": "^13.6.20"
3839
},
3940
"devDependencies": {
40-
"@types/codemirror": "^5.60.15",
4141
"@testing-library/dom": "^10.4.0",
4242
"@testing-library/jest-dom": "^6.6.3",
4343
"@testing-library/react": "^16.0.1",
44+
"@types/codemirror": "^5.60.15",
4445
"@types/jest": "^29.5.14",
4546
"@types/node": "^20",
4647
"@types/peerjs": "^1.1.0",

apps/frontend/pnpm-lock.yaml

Lines changed: 18 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)