-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from CS3219-AY2425S1/titus/add-ui-for-testcases
feat: update frontend ui for testcases
- Loading branch information
Showing
8 changed files
with
776 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.