some update
This commit is contained in:
parent
c85d3e66ac
commit
e74b133c7a
@ -12,10 +12,10 @@ import (
|
||||
"github.com/themakers/hlog"
|
||||
"go.uber.org/zap"
|
||||
dalBS "penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/service"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/healthchecks"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/savewc"
|
||||
)
|
||||
|
5
go.mod
5
go.mod
@ -10,7 +10,7 @@ require (
|
||||
github.com/skeris/appInit v1.0.2
|
||||
github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf
|
||||
go.uber.org/zap v1.26.0
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240219175507-7f8de986a6dc
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240313164312-4560248259a0
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240219182009-751c74a08732
|
||||
)
|
||||
|
||||
@ -19,6 +19,7 @@ require (
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0 // indirect
|
||||
github.com/golang-migrate/migrate/v4 v4.17.0 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
@ -50,5 +51,5 @@ require (
|
||||
google.golang.org/protobuf v1.32.0 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d // indirect
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af // indirect
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240313165712-63460dc78d4f // indirect
|
||||
)
|
||||
|
10
go.sum
10
go.sum
@ -32,6 +32,8 @@ github.com/gofiber/fiber/v2 v2.52.0 h1:S+qXi7y+/Pgvqq4DrSmREGiFwtB7Bu6+QFLuIHYw/
|
||||
github.com/gofiber/fiber/v2 v2.52.0/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
|
||||
github.com/golang-migrate/migrate/v4 v4.17.0 h1:rd40H3QXU0AA4IoLllFcEAEo9dYKRHYND2gB4p7xcaU=
|
||||
github.com/golang-migrate/migrate/v4 v4.17.0/go.mod h1:+Cp2mtLP4/aXDTKb9wmXYitdrNx2HGs45rbWAo6OsKM=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
@ -187,9 +189,9 @@ gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d h1:gbaDt35HMDqOK84WYmDIlXMI7rstUcRqNttaT6Kx1do=
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240219175507-7f8de986a6dc h1:jIN9XyfL/FJ/eSsYopE1olHboituwmisC1Sf1d4nhWE=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240219175507-7f8de986a6dc/go.mod h1:OXYvMlc+3qfcllPTywUB3QDiPK1kwsMNdZMTlPXFIdo=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240313164312-4560248259a0 h1:YbffFOWneoINvEqCWClf5Zatu/a0VNo9RM0nYveCzhk=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240313164312-4560248259a0/go.mod h1:JgbH8cdAJBr3jx3BuY5nnuTyMdZ1XkRxo8a3w4Y3C0Y=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240313165712-63460dc78d4f h1:bb6dpmEKUOA6XjNyW66A8lPNRl4pISrZ2q/7J0C3mkk=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240313165712-63460dc78d4f/go.mod h1:1L60BR27jRadx5JtRKZHYPM5Lilz5Yg+geFSgY7eCnM=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240219182009-751c74a08732 h1:FiUWe2OkFZsTFyoKZIE2uMMEPS0JRetHDG1CWdmayvs=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240219182009-751c74a08732/go.mod h1:AV230HAt2MMzZVdBNxyBaOFmZ4KY4ieDBpBhokIPlPs=
|
||||
|
@ -1,28 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/xid"
|
||||
)
|
||||
|
||||
type ContextKey string
|
||||
|
||||
const (
|
||||
SessionKey = "X-SessionKey"
|
||||
)
|
||||
|
||||
func AnswererChain() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
session := c.Get(SessionKey)
|
||||
|
||||
if session == "" {
|
||||
session := xid.New().String()
|
||||
c.Set(SessionKey, session)
|
||||
c.Locals(ContextKey(SessionKey), session)
|
||||
} else {
|
||||
c.Locals(ContextKey(SessionKey), session)
|
||||
}
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
}
|
@ -5,8 +5,8 @@ import (
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/middleware"
|
||||
quizdal "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -56,9 +56,10 @@ type GetQuizDataReq struct {
|
||||
|
||||
// GetQuizDataResp response with prepared data for user
|
||||
type GetQuizDataResp struct {
|
||||
Settings ShavedQuiz `json:"settings"`
|
||||
Items []ShavedQuestion `json:"items"`
|
||||
Count uint64 `json:"cnt"`
|
||||
Settings ShavedQuiz `json:"settings"`
|
||||
Items []ShavedQuestion `json:"items"`
|
||||
Count uint64 `json:"cnt"`
|
||||
ShowBadge bool `json:"show_badge"`
|
||||
}
|
||||
|
||||
// ShavedQuiz shortened struct for delivery data to customer
|
||||
@ -125,6 +126,24 @@ func (s *Service) GetQuizData(c *fiber.Ctx) error {
|
||||
return c.Status(fiber.StatusGone).SendString("quiz timeouted")
|
||||
}
|
||||
|
||||
account, err := s.dal.AccountRepo.GetAccountByID(c.Context(), quiz.AccountId)
|
||||
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("can`t get account by quiz.AccountId")
|
||||
}
|
||||
|
||||
showBadge := true
|
||||
|
||||
fmt.Println("PRIVI", account.Privileges)
|
||||
if priv, ok := account.Privileges["squizHideBadge"]; ok {
|
||||
expiration := priv.CreatedAt.Add(time.Duration(priv.Amount) * 24 * time.Hour)
|
||||
fmt.Println("PRIVI1", priv, expiration, time.Now().Before(expiration))
|
||||
|
||||
if time.Now().Before(expiration) {
|
||||
showBadge = false
|
||||
}
|
||||
}
|
||||
|
||||
questions, cnt, err := s.dal.QuestionRepo.GetQuestionList(
|
||||
c.Context(),
|
||||
req.Limit,
|
||||
@ -136,8 +155,9 @@ func (s *Service) GetQuizData(c *fiber.Ctx) error {
|
||||
}
|
||||
|
||||
result := GetQuizDataResp{
|
||||
Count: cnt,
|
||||
Items: []ShavedQuestion{},
|
||||
Count: cnt,
|
||||
Items: []ShavedQuestion{},
|
||||
ShowBadge: showBadge,
|
||||
}
|
||||
|
||||
if req.NeedConfig {
|
||||
@ -266,6 +286,13 @@ func (s *Service) PutAnswersOnePiece(c *fiber.Ctx) error {
|
||||
ans.CreatedAt = time.Now()
|
||||
answers = append(answers, ans)
|
||||
if ans.Result {
|
||||
content := model.ResultContent{}
|
||||
err := json.Unmarshal([]byte(ans.Content), &content)
|
||||
if err != nil {
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("error unmarshalling answer content: " + err.Error())
|
||||
}
|
||||
ans.Email = content.Email
|
||||
|
||||
s.workerSendClientCh <- ans
|
||||
trueRes = append(trueRes, ans)
|
||||
}
|
||||
@ -283,6 +310,12 @@ func (s *Service) PutAnswersOnePiece(c *fiber.Ctx) error {
|
||||
|
||||
stored, ers := s.dal.AnswerRepo.CreateAnswers(c.Context(), answers, cs, fp, quiz.Id)
|
||||
if len(ers) != 0 {
|
||||
for _, err := range ers {
|
||||
if strings.Contains(err.Error(), "duplicate key value") {
|
||||
return c.Status(fiber.StatusAlreadyReported).SendString("User has already passed the quiz")
|
||||
}
|
||||
}
|
||||
|
||||
return c.Status(fiber.StatusInternalServerError).SendString("some errors are casualted: " + fmt.Sprint(ers))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user