move minipart to answer from core
This commit is contained in:
parent
3b9ac999ed
commit
192d3e76af
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,
|
||||||
|
@ -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("/quiz/logo", s.MiniPart)
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,3 +403,33 @@ 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())
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("OLOLO", string(shifr))
|
||||||
|
|
||||||
|
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