diff --git a/apis/cache.go b/apis/cache.go index d21ea4c..2fc8bec 100644 --- a/apis/cache.go +++ b/apis/cache.go @@ -227,6 +227,8 @@ LOAD_FILES: GlobalQuestionConfig.Lock() GlobalQuestionConfig.Questions = newQuestions GlobalQuestionConfig.CurrentVersion = newQuestionCurrentVersion + jsonQuestions, _ := json.Marshal(GlobalQuestionConfig.Questions) + log.Debug().Msgf("questionsResponse: %s", string(jsonQuestions)) GlobalQuestionConfig.Unlock() return nil diff --git a/apis/question.go b/apis/question.go index f6b6b5a..1b23e92 100644 --- a/apis/question.go +++ b/apis/question.go @@ -1,15 +1,17 @@ package apis import ( + "encoding/json" "fmt" "sort" + . "auth_next/models" + "github.com/gofiber/fiber/v2" "github.com/opentreehole/go-common" + "github.com/rs/zerolog/log" "golang.org/x/exp/rand" "golang.org/x/exp/slices" - - . "auth_next/models" ) // RetrieveQuestions godoc @@ -128,8 +130,6 @@ func RetrieveQuestions(c *fiber.Ctx) (err error) { tmpQuestions = append(tmpQuestions, chosenCampusQuestions[:numberOfCampusQuestions]...) } - - if !inOrder { rand.Shuffle(len(tmpQuestions), func(i, j int) { tmpQuestions[i], tmpQuestions[j] = tmpQuestions[j], tmpQuestions[i] @@ -144,6 +144,9 @@ func RetrieveQuestions(c *fiber.Ctx) (err error) { questionsResponse.Questions[i] = *question } + jsonQuestions, _ := json.Marshal(questionsResponse) + log.Debug().Msgf("questionsResponse: %s", string(jsonQuestions)) + // shuffle options for i := range questionsResponse.Questions { options := questionsResponse.Questions[i].Options // copy slice pointer only @@ -162,6 +165,9 @@ func RetrieveQuestions(c *fiber.Ctx) (err error) { questionsResponse.Questions[i].Option = questionsResponse.Questions[i].Options } + jsonQuestions, _ = json.Marshal(questionsResponse) + log.Debug().Msgf("questionsResponse: %s", string(jsonQuestions)) + return c.JSON(questionsResponse) }