Merge branch 'staging' into 'hlog'

# Conflicts:
#   go.mod
#   go.sum
#   service/quiz_svc.go
This commit is contained in:
Mikhail 2024-06-11 16:50:55 +00:00
commit 2cb6d9c1dc
9 changed files with 72 additions and 50 deletions

@ -1,4 +1,4 @@
FROM golang:alpine as build FROM penahub.gitlab.yandexcloud.net:5050/devops/dockerhub-backup/golang as build
WORKDIR /app WORKDIR /app
RUN apk add git RUN apk add git
COPY . . COPY . .
@ -8,7 +8,7 @@ RUN git config --global url."https://buildToken:glpat-axA8ttckx3aPf_xd2Dym@penah
RUN go mod download RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o core RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o core
FROM alpine as prod FROM penahub.gitlab.yandexcloud.net:5050/devops/dockerhub-backup/alpine as prod
COPY --from=build /app/core . COPY --from=build /app/core .
COPY --from=build /app/schema /schema COPY --from=build /app/schema /schema
EXPOSE 1488 EXPOSE 1488

@ -15,7 +15,6 @@ 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"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/initialize" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/initialize"
@ -62,9 +61,6 @@ type Options struct {
HubAdminUrl string `env:"HUB_ADMIN_URL" default:"http://localhost:8001/"` HubAdminUrl string `env:"HUB_ADMIN_URL" default:"http://localhost:8001/"`
ServiceName string `env:"SERVICE_NAME" default:"squiz"` ServiceName string `env:"SERVICE_NAME" default:"squiz"`
AuthServiceURL string `env:"AUTH_URL" default:"http://localhost:8000/"` AuthServiceURL string `env:"AUTH_URL" default:"http://localhost:8000/"`
RedirectURL string `env:"REDIRECT_URL" default:"https://squiz.pena.digital"`
PubKey string `env:"PUBLIC_KEY"`
PrivKey string `env:"PRIVATE_KEY"`
GrpcHost string `env:"GRPC_HOST" default:"localhost"` GrpcHost string `env:"GRPC_HOST" default:"localhost"`
GrpcPort string `env:"GRPC_PORT" default:"9000"` GrpcPort string `env:"GRPC_PORT" default:"9000"`
KafkaBrokers string `env:"KAFKA_BROKERS" default:"localhost:9092"` KafkaBrokers string `env:"KAFKA_BROKERS" default:"localhost:9092"`
@ -163,7 +159,6 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
Port: options.GrpcPort, Port: options.GrpcPort,
}) })
encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey)
app := fiber.New() app := fiber.New()
app.Use(middleware.JWTAuth()) app.Use(middleware.JWTAuth())
app.Use(log_mw.ContextLogger(loggerHlog)) app.Use(log_mw.ContextLogger(loggerHlog))
@ -173,8 +168,6 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
svc := service.New(service.Deps{ svc := service.New(service.Deps{
Dal: pgdal, Dal: pgdal,
AuthClient: authClient, AuthClient: authClient,
RedirectURl: options.RedirectURL,
Encrypt: encrypt,
Producer: producer, Producer: producer,
ServiceName: options.ServiceName, ServiceName: options.ServiceName,
}) })

@ -1,3 +1,4 @@
version: "3"
services: services:
core: core:
hostname: squiz-core hostname: squiz-core

1
go.mod

@ -50,7 +50,6 @@ require (
github.com/richardlehane/msoleps v1.0.3 // indirect github.com/richardlehane/msoleps v1.0.3 // indirect
github.com/rivo/uniseg v0.4.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect
github.com/rs/xid v1.5.0 // indirect github.com/rs/xid v1.5.0 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
github.com/twmb/franz-go/pkg/kmsg v1.8.0 // indirect github.com/twmb/franz-go/pkg/kmsg v1.8.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.53.0 // indirect github.com/valyala/fasthttp v1.53.0 // indirect

1
go.sum

@ -262,7 +262,6 @@ google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFW
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=

@ -1478,6 +1478,49 @@ paths:
type: string type: string
'500': '500':
description: Failed copy quiz description: Failed copy quiz
content:
application/json:
schema:
type: object
properties:
message:
type: string
/account/manualdone:
post:
description: метод для декремента привилегии quizManual у пользователя
requestBody:
content:
'application/json':
schema:
type: object
properties:
id:
type: string
description: id пользователя у которого отнимается штука привилегии
required: true
responses:
'200':
description: ОК, успешно отнялась 1 штука
'400':
description: Bad request, ошибка в теле запроса
content:
application/json:
schema:
type: object
properties:
message:
type: string
'404':
description: Not Found, у пользователя не нашлось такой привилегии либо она кончилась и воркер до нее еще не добрался
content:
application/json:
schema:
type: object
properties:
message:
type: string
'500':
description: Internal Srv Error
content: content:
application/json: application/json:
schema: schema:

@ -2,10 +2,12 @@ package service
import ( import (
"database/sql" "database/sql"
"errors"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw" "penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw"
"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/pj_errors"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/models" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/models"
"time" "time"
@ -211,3 +213,26 @@ func (s *Service) getAccounts(ctx *fiber.Ctx) error {
return ctx.Status(fiber.StatusOK).JSON(response) return ctx.Status(fiber.StatusOK).JSON(response)
} }
func (s *Service) ManualDone(ctx *fiber.Ctx) error {
var req struct {
Id string `json:"id"`
}
if err := ctx.BodyParser(&req); err != nil {
return ctx.Status(fiber.StatusBadRequest).SendString("Invalid request data")
}
if req.Id == "" {
return ctx.Status(fiber.StatusBadRequest).SendString("User id is required")
}
err := s.dal.AccountRepo.ManualDone(ctx.Context(), req.Id)
if err != nil {
if errors.Is(err, pj_errors.ErrNotFound) {
return ctx.Status(fiber.StatusNotFound).SendString("user don't have this privilege")
}
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
}
return ctx.SendStatus(fiber.StatusOK)
}

@ -1,7 +1,6 @@
package service package service
import ( import (
"fmt"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"net/url" "net/url"
"penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw" "penahub.gitlab.yandexcloud.net/backend/penahub_common/log_mw"
@ -486,36 +485,6 @@ func (s *Service) QuizMove(ctx *fiber.Ctx) error {
return ctx.Status(fiber.StatusOK).JSON(resp) 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())
}
fmt.Println("OLOLO", string(shifr))
ctx.Cookie(&fiber.Cookie{
Name: "quizUser",
Value: url.QueryEscape(string(shifr)),
})
return ctx.Redirect(s.redirectURl, fiber.StatusFound)
}
func (s *Service) TemplateCopy(ctx *fiber.Ctx) error { func (s *Service) TemplateCopy(ctx *fiber.Ctx) error {
accountID, ok := middleware.GetAccountId(ctx) accountID, ok := middleware.GetAccountId(ctx)
if !ok { if !ok {

@ -3,7 +3,6 @@ package service
import ( import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal" "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers"
"penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth"
) )
@ -11,8 +10,6 @@ import (
// Service is an entity for http requests handling // Service is an entity for http requests handling
type Service struct { type Service struct {
dal *dal.DAL dal *dal.DAL
redirectURl string
encrypt *utils.Encrypt
authClient *auth.AuthClient authClient *auth.AuthClient
producer *brokers.Producer producer *brokers.Producer
serviceName string serviceName string
@ -20,8 +17,6 @@ type Service struct {
type Deps struct { type Deps struct {
Dal *dal.DAL Dal *dal.DAL
RedirectURl string
Encrypt *utils.Encrypt
AuthClient *auth.AuthClient AuthClient *auth.AuthClient
Producer *brokers.Producer Producer *brokers.Producer
ServiceName string ServiceName string
@ -30,8 +25,6 @@ type Deps struct {
func New(deps Deps) *Service { func New(deps Deps) *Service {
return &Service{ return &Service{
dal: deps.Dal, dal: deps.Dal,
redirectURl: deps.RedirectURl,
encrypt: deps.Encrypt,
authClient: deps.AuthClient, authClient: deps.AuthClient,
producer: deps.Producer, producer: deps.Producer,
serviceName: deps.ServiceName, serviceName: deps.ServiceName,
@ -49,7 +42,6 @@ func (s *Service) Register(app *fiber.App) {
app.Delete("/quiz/delete", s.DeleteQuiz) app.Delete("/quiz/delete", s.DeleteQuiz)
app.Patch("/quiz/archive", s.ArchiveQuiz) app.Patch("/quiz/archive", s.ArchiveQuiz)
app.Post("/quiz/move", s.QuizMove) app.Post("/quiz/move", s.QuizMove)
app.Get("/quiz/logo", s.MiniPart)
app.Post("/quiz/template", s.TemplateCopy) app.Post("/quiz/template", s.TemplateCopy)
// question manipulating handlers // question manipulating handlers
@ -67,6 +59,7 @@ func (s *Service) Register(app *fiber.App) {
app.Get("/accounts", s.getAccounts) app.Get("/accounts", s.getAccounts)
app.Get("/privilege/:userId", s.getPrivilegeByUserID) app.Get("/privilege/:userId", s.getPrivilegeByUserID)
app.Delete("/account/:userId", s.deleteAccountByUserID) app.Delete("/account/:userId", s.deleteAccountByUserID)
app.Post("/account/manualdone", s.ManualDone)
// result handlers // result handlers
app.Post("/results/getResults/:quizId", s.GetResultsByQuizID) app.Post("/results/getResults/:quizId", s.GetResultsByQuizID)