Skip to content

Commit

Permalink
Merge pull request #83 from CS3219-AY2425S1/titus/add-ui-for-testcases
Browse files Browse the repository at this point in the history
feat: update frontend ui for testcases
  • Loading branch information
chiaryan authored Nov 13, 2024
2 parents 8a31a6f + 1b8eddb commit c236012
Show file tree
Hide file tree
Showing 8 changed files with 776 additions and 102 deletions.
71 changes: 71 additions & 0 deletions apps/execution-service/handlers/readall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package handlers

import (
"encoding/json"
"execution-service/models"
"execution-service/utils"
"net/http"

"github.com/go-chi/chi/v5"
"google.golang.org/api/iterator"
)

func (s *Service) ReadAllTests(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

questionDocRefId := chi.URLParam(r, "questionDocRefId")
if questionDocRefId == "" {
http.Error(w, "questionDocRefId is required", http.StatusBadRequest)
return
}

iter := s.Client.Collection("tests").Where("questionDocRefId", "==", questionDocRefId).Limit(1).Documents(ctx)
doc, err := iter.Next()
if err != nil {
if err == iterator.Done {
http.Error(w, "Test not found", http.StatusNotFound)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer iter.Stop()

var test models.Test
if err := doc.DataTo(&test); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

_, hiddenTestCases, err := utils.GetTestLengthAndUnexecutedCases(test.HiddenTestCases)

var hiddenTests []models.HiddenTest
for _, hiddenTestCase := range hiddenTestCases {
hiddenTests = append(hiddenTests, models.HiddenTest{
Input: hiddenTestCase.Input,
Expected: hiddenTestCase.Expected,
})
}

_, visibleTestCases, err := utils.GetTestLengthAndUnexecutedCases(test.VisibleTestCases)

var visibleTests []models.VisibleTest
for _, visibleTestCase := range visibleTestCases {
visibleTests = append(visibleTests, models.VisibleTest{
Input: visibleTestCase.Input,
Expected: visibleTestCase.Expected,
})
}

allTests := models.AllTests{
VisibleTests: visibleTests,
HiddenTests: hiddenTests,
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(allTests)
}

//curl -X GET http://localhost:8083/tests/bmzFyLMeSOoYU99pi4yZ/ \
//-H "Content-Type: application/json"
File renamed without changes.
1 change: 1 addition & 0 deletions apps/execution-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func registerRoutes(r *chi.Mux, service *handlers.Service) {
r.Put("/", service.UpdateTest)
r.Delete("/", service.DeleteTest)
r.Get("/", service.ReadVisibleTests)
r.Get("/readall", service.ReadAllTests)
r.Post("/execute", service.ExecuteVisibleAndCustomTests)
r.Post("/submit", service.ExecuteVisibleAndHiddenTestsAndSubmit)
})
Expand Down
10 changes: 10 additions & 0 deletions apps/execution-service/models/visibleTest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ type VisibleTest struct {
Input string `json:"input"`
Expected string `json:"expected"`
}

type HiddenTest struct {
Input string `json:"input"`
Expected string `json:"expected"`
}

type AllTests struct {
VisibleTests []VisibleTest `json:"visibleTests"`
HiddenTests []HiddenTest `json:"hiddenTests"`
}
3 changes: 2 additions & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@
"react-use-websocket": "^4.9.0",
"sass": "^1.79.2",
"typeface-montserrat": "^1.1.13",
"uuid": "^11.0.3",
"y-codemirror.next": "^0.3.5",
"y-webrtc": "^10.3.0",
"yjs": "^13.6.20"
},
"devDependencies": {
"@types/codemirror": "^5.60.15",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@types/codemirror": "^5.60.15",
"@types/jest": "^29.5.14",
"@types/node": "^20",
"@types/peerjs": "^1.1.0",
Expand Down
27 changes: 18 additions & 9 deletions apps/frontend/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c236012

Please sign in to comment.