Skip to content

Commit ed24f5a

Browse files
committed
feat: add read for hidden tests
1 parent 4243ae9 commit ed24f5a

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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) ReadHiddenTests(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+
w.Header().Set("Content-Type", "application/json")
51+
w.WriteHeader(http.StatusOK)
52+
json.NewEncoder(w).Encode(hiddenTests)
53+
}
54+
55+
//curl -X GET http://localhost:8083/tests/bmzFyLMeSOoYU99pi4yZ/ \
56+
//-H "Content-Type: application/json"

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("/hidden", service.ReadHiddenTests)
9697
r.Post("/execute", service.ExecuteVisibleAndCustomTests)
9798
r.Post("/submit", service.ExecuteVisibleAndHiddenTestsAndSubmit)
9899
})

0 commit comments

Comments
 (0)