Merge branch 'quizLogo' into 'staging'
Перенос обработчика мини партнёрки /logo в сервис, который отвечает за обработку действий респондентов See merge request backend/quiz/answerer!3
This commit is contained in:
commit
b02599e180
17
app/app.go
17
app/app.go
@ -18,6 +18,7 @@ import (
|
|||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/healthchecks"
|
"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/middleware"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
@ -58,6 +59,9 @@ type Options struct {
|
|||||||
RedisHost string `env:"REDIS_HOST"`
|
RedisHost string `env:"REDIS_HOST"`
|
||||||
RedisPassword string `env:"REDIS_PASSWORD"`
|
RedisPassword string `env:"REDIS_PASSWORD"`
|
||||||
RedisDB uint64 `env:"REDIS_DB"`
|
RedisDB uint64 `env:"REDIS_DB"`
|
||||||
|
RedirectURL string `env:"REDIRECT_URL" default:"https://squiz.pena.digital"`
|
||||||
|
PubKey string `env:"PUBLIC_KEY"`
|
||||||
|
PrivKey string `env:"PRIVATE_KEY"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
|
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
|
||||||
@ -108,7 +112,6 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
zapLogger.Info("config", zap.Any("options", options))
|
zapLogger.Info("config", zap.Any("options", options))
|
||||||
//init redis
|
//init redis
|
||||||
redisClient := redis.NewClient(&redis.Options{
|
redisClient := redis.NewClient(&redis.Options{
|
||||||
@ -117,13 +120,23 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
|
|||||||
DB: int(options.RedisDB),
|
DB: int(options.RedisDB),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey)
|
||||||
|
|
||||||
workerSendClientCh := make(chan model.Answer, 50)
|
workerSendClientCh := make(chan model.Answer, 50)
|
||||||
workerRespondentCh := make(chan []model.Answer, 50)
|
workerRespondentCh := make(chan []model.Answer, 50)
|
||||||
blobstore, err := dalBS.New(ctx, minioClient)
|
blobstore, err := dalBS.New(ctx, minioClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
svc := service.New(blobstore, pgdal, workerRespondentCh, workerSendClientCh)
|
//svc := service.New(blobstore, pgdal, workerRespondentCh, workerSendClientCh)
|
||||||
|
svc := service.New(service.ServiceDeps{
|
||||||
|
Store: blobstore,
|
||||||
|
Dal: pgdal,
|
||||||
|
WorkerSendClientCh: workerSendClientCh,
|
||||||
|
WorkerRespondentCh: workerRespondentCh,
|
||||||
|
Encrypt: encrypt,
|
||||||
|
RedirectURl: options.RedirectURL,
|
||||||
|
})
|
||||||
|
|
||||||
saveRespWcData := savewc.DepsForResp{
|
saveRespWcData := savewc.DepsForResp{
|
||||||
WorkerRespondentCh: workerRespondentCh,
|
WorkerRespondentCh: workerRespondentCh,
|
||||||
|
@ -16,6 +16,9 @@ services:
|
|||||||
PG_CRED: 'host=10.8.0.5 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable'
|
PG_CRED: 'host=10.8.0.5 port=5433 user=squiz password=Redalert2 dbname=squiz sslmode=disable'
|
||||||
REDIS_HOST: '10.8.0.5:6379'
|
REDIS_HOST: '10.8.0.5:6379'
|
||||||
REDIS_PASSWORD: 'Redalert2'
|
REDIS_PASSWORD: 'Redalert2'
|
||||||
REDIS_DB: 2
|
REDIS_DB: 2
|
||||||
|
PUBLIC_KEY: $PUBLIC_KEY
|
||||||
|
PRIVATE_KEY: $PRIVATE_KEY
|
||||||
|
|
||||||
ports:
|
ports:
|
||||||
- 10.8.0.5:1491:1490
|
- 10.8.0.5:1491:1490
|
||||||
|
@ -4,10 +4,12 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
"net/url"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/dal"
|
"penahub.gitlab.yandexcloud.net/backend/quiz/answerer.git/dal"
|
||||||
quizdal "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
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/middleware"
|
||||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||||
|
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -27,22 +29,36 @@ type Service struct {
|
|||||||
m sync.Mutex
|
m sync.Mutex
|
||||||
workerRespondentCh chan<- []model.Answer
|
workerRespondentCh chan<- []model.Answer
|
||||||
workerSendClientCh chan<- model.Answer
|
workerSendClientCh chan<- model.Answer
|
||||||
|
encrypt *utils.Encrypt
|
||||||
|
redirectURl string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(s *dal.Storer, q *quizdal.DAL, workerRespondentCh chan<- []model.Answer, workerSendClientCh chan<- model.Answer) *Service {
|
type ServiceDeps struct {
|
||||||
|
Store *dal.Storer
|
||||||
|
Dal *quizdal.DAL
|
||||||
|
WorkerRespondentCh chan<- []model.Answer
|
||||||
|
WorkerSendClientCh chan<- model.Answer
|
||||||
|
Encrypt *utils.Encrypt
|
||||||
|
RedirectURl string
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(deps ServiceDeps) *Service {
|
||||||
return &Service{
|
return &Service{
|
||||||
store: s,
|
store: deps.Store,
|
||||||
dal: q,
|
dal: deps.Dal,
|
||||||
m: sync.Mutex{},
|
m: sync.Mutex{},
|
||||||
batch: []model.Answer{},
|
batch: []model.Answer{},
|
||||||
workerRespondentCh: workerRespondentCh,
|
workerRespondentCh: deps.WorkerRespondentCh,
|
||||||
workerSendClientCh: workerSendClientCh,
|
workerSendClientCh: deps.WorkerSendClientCh,
|
||||||
|
encrypt: deps.Encrypt,
|
||||||
|
redirectURl: deps.RedirectURl,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Register(app *fiber.App) *fiber.App {
|
func (s *Service) Register(app *fiber.App) *fiber.App {
|
||||||
app.Post("/answer", s.PutAnswersOnePiece)
|
app.Post("/answer", s.PutAnswersOnePiece)
|
||||||
app.Post("/settings", s.GetQuizData)
|
app.Post("/settings", s.GetQuizData)
|
||||||
|
app.Get("/logo", s.MiniPart)
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +150,6 @@ func (s *Service) GetQuizData(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
showBadge := true
|
showBadge := true
|
||||||
|
|
||||||
fmt.Println("PRIVRRRR", account.ID, account.Privileges)
|
|
||||||
if priv, ok := account.Privileges["squizHideBadge"]; ok {
|
if priv, ok := account.Privileges["squizHideBadge"]; ok {
|
||||||
expiration := priv.CreatedAt.Add(time.Duration(priv.Amount) * 24 * time.Hour)
|
expiration := priv.CreatedAt.Add(time.Duration(priv.Amount) * 24 * time.Hour)
|
||||||
|
|
||||||
@ -387,3 +402,31 @@ func (s *Service) PutAnswersOnePiece(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
return c.Status(fiber.StatusOK).JSON(response)
|
return c.Status(fiber.StatusOK).JSON(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) MiniPart(ctx *fiber.Ctx) error {
|
||||||
|
qid := ctx.Query("q")
|
||||||
|
if qid == "" {
|
||||||
|
return ctx.Status(fiber.StatusBadRequest).SendString("qid is nil")
|
||||||
|
}
|
||||||
|
ctx.Cookie(&fiber.Cookie{
|
||||||
|
Name: "quizFrom",
|
||||||
|
Value: qid,
|
||||||
|
})
|
||||||
|
|
||||||
|
userID, err := s.dal.AccountRepo.GetQidOwner(ctx.Context(), qid)
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
shifr, err := s.encrypt.EncryptStr(userID)
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Status(fiber.StatusInternalServerError).SendString(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Cookie(&fiber.Cookie{
|
||||||
|
Name: "quizUser",
|
||||||
|
Value: url.QueryEscape(string(shifr)),
|
||||||
|
})
|
||||||
|
|
||||||
|
return ctx.Redirect(s.redirectURl, fiber.StatusFound)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user