Skip to content

Commit

Permalink
Merge pull request #22 from ppolariss/main
Browse files Browse the repository at this point in the history
chore: debug question
  • Loading branch information
JingYiJun authored Jul 29, 2024
2 parents 1965872 + 480c7a0 commit 608a351
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apis/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions apis/question.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit 608a351

Please sign in to comment.