init new route logo

This commit is contained in:
Pavel 2024-03-22 15:42:52 +03:00
parent 21e60013c8
commit e5b2e5a4ff
5 changed files with 55 additions and 9 deletions

@ -13,6 +13,7 @@ import (
"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/common.git/utils"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/service"
)
@ -52,6 +53,9 @@ type Options struct {
HubAdminUrl string `env:"HUB_ADMIN_URL"`
ServiceName string `env:"SERVICE_NAME" default:"squiz"`
AuthServiceURL string `env:"AUTH_URL"`
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) {
@ -113,12 +117,18 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
fmt.Println("Failed to publish privileges", err)
}
encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey)
app := fiber.New()
app.Use(middleware.JWTAuth())
app.Get("/liveness", healthchecks.Liveness)
app.Get("/readiness", healthchecks.Readiness(&workerErr)) //todo parametrized readiness. should discuss ready reason
svc := service.New(pgdal)
svc := service.New(service.Deps{
Dal: pgdal,
RedirectURl: options.RedirectURL,
Encrypt: encrypt,
})
svc.Register(app)
logger.Emit(InfoSvcReady{})

2
go.mod

@ -15,7 +15,7 @@ require (
github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf
go.uber.org/zap v1.26.0
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240202120244-c4ef330cfe5d
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240319164920-735ebe63cb8f
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240322123636-95a2f52339d5
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3
)

6
go.sum

@ -186,9 +186,7 @@ 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-20240318113600-bb9068452254 h1:M5sseXv0uqrOpi3nOBdOk1Q2PKYCkzi2ymXqoYHyOfY=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240318113600-bb9068452254/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240319164920-735ebe63cb8f h1:wTc60/tCk0s7Gsfh/0lp9xlHKxtsXBzVkbBajoppt7c=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240319164920-735ebe63cb8f/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240322123636-95a2f52339d5 h1:c9/hwlNC5nd/6M61ULCWg9BQl5wWeK21oQIaEEEGe8c=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240322123636-95a2f52339d5/go.mod h1:okduDAq0NVVDcM+TMyrd4mVXzBMeTzYI2B2/yi1sL1Y=
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3 h1:BLHIUnJAttW9OAW7A63H9ON/HPhXdpBa/YPUQWD4ORA=
penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240313171802-7da5fbb4caf3/go.mod h1:/BFcX4F10DRuFuAHlwkKO+1QAXPL4i49x1tsrTwxlqE=

@ -452,3 +452,31 @@ func (s *Service) QuizMove(ctx *fiber.Ctx) error {
return ctx.Status(fiber.StatusOK).JSON(resp)
}
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: string(shifr),
})
return ctx.Redirect(s.redirectURl, fiber.StatusFound)
}

@ -3,15 +3,24 @@ package service
import (
"github.com/gofiber/fiber/v2"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
)
// Service is an entity for http requests handling
type Service struct {
dal *dal.DAL
dal *dal.DAL
redirectURl string
encrypt *utils.Encrypt
}
func New(d *dal.DAL) *Service {
return &Service{dal: d}
type Deps struct {
Dal *dal.DAL
RedirectURl string
Encrypt *utils.Encrypt
}
func New(deps Deps) *Service {
return &Service{dal: deps.Dal, redirectURl: deps.RedirectURl, encrypt: deps.Encrypt}
}
// Register is a function for add handlers of service to external multiplexer
@ -25,6 +34,7 @@ func (s *Service) Register(app *fiber.App) {
app.Delete("/quiz/delete", s.DeleteQuiz)
app.Patch("/quiz/archive", s.ArchiveQuiz)
app.Post("/quiz/move", s.QuizMove)
app.Get("/quiz/logo", s.MiniPart)
// question manipulating handlers
app.Post("/question/create", s.CreateQuestion)