From b8a9c4871640aeeb79f620f0412cf078c5c40903 Mon Sep 17 00:00:00 2001 From: Pavel Date: Sat, 1 Jun 2024 16:26:25 +0300 Subject: [PATCH 1/4] delete minipart from core --- app/app.go | 7 ------- service/quiz_svc.go | 32 -------------------------------- service/service.go | 8 -------- 3 files changed, 47 deletions(-) diff --git a/app/app.go b/app/app.go index fe7f058..9850d1c 100644 --- a/app/app.go +++ b/app/app.go @@ -13,7 +13,6 @@ 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/brokers" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/initialize" @@ -58,9 +57,6 @@ type Options struct { HubAdminUrl string `env:"HUB_ADMIN_URL" default:"http://localhost:8001/"` ServiceName string `env:"SERVICE_NAME" default:"squiz"` 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"` GrpcPort string `env:"GRPC_PORT" default:"9000"` KafkaBrokers string `env:"KAFKA_BROKERS" default:"localhost:9092"` @@ -147,7 +143,6 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co Port: options.GrpcPort, }) - encrypt := utils.NewEncrypt(options.PubKey, options.PrivKey) app := fiber.New() app.Use(middleware.JWTAuth()) app.Get("/liveness", healthchecks.Liveness) @@ -156,8 +151,6 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co svc := service.New(service.Deps{ Dal: pgdal, AuthClient: authClient, - RedirectURl: options.RedirectURL, - Encrypt: encrypt, Producer: producer, ServiceName: options.ServiceName, }) diff --git a/service/quiz_svc.go b/service/quiz_svc.go index 56a74b1..d63bae8 100644 --- a/service/quiz_svc.go +++ b/service/quiz_svc.go @@ -1,9 +1,7 @@ package service import ( - "fmt" "github.com/gofiber/fiber/v2" - "net/url" "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/repository/quiz" @@ -455,36 +453,6 @@ 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()) - } - - 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 { accountID, ok := middleware.GetAccountId(ctx) if !ok { diff --git a/service/service.go b/service/service.go index 038690f..09f96e9 100644 --- a/service/service.go +++ b/service/service.go @@ -3,7 +3,6 @@ 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" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/clients/auth" ) @@ -11,8 +10,6 @@ import ( // Service is an entity for http requests handling type Service struct { dal *dal.DAL - redirectURl string - encrypt *utils.Encrypt authClient *auth.AuthClient producer *brokers.Producer serviceName string @@ -20,8 +17,6 @@ type Service struct { type Deps struct { Dal *dal.DAL - RedirectURl string - Encrypt *utils.Encrypt AuthClient *auth.AuthClient Producer *brokers.Producer ServiceName string @@ -30,8 +25,6 @@ type Deps struct { func New(deps Deps) *Service { return &Service{ dal: deps.Dal, - redirectURl: deps.RedirectURl, - encrypt: deps.Encrypt, authClient: deps.AuthClient, producer: deps.Producer, serviceName: deps.ServiceName, @@ -49,7 +42,6 @@ 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) app.Post("/quiz/template", s.TemplateCopy) // question manipulating handlers From 9cbf84ebd23d49d7abd874c9c0edff4b39808c48 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 3 Jun 2024 16:21:21 +0300 Subject: [PATCH 2/4] starting manual done --- service/account_svc.go | 15 +++++++++++++++ service/service.go | 1 + 2 files changed, 16 insertions(+) diff --git a/service/account_svc.go b/service/account_svc.go index d9b6832..b20e3be 100644 --- a/service/account_svc.go +++ b/service/account_svc.go @@ -203,3 +203,18 @@ func (s *Service) getAccounts(ctx *fiber.Ctx) error { 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") + } + + return ctx.SendStatus(fiber.StatusOK) +} diff --git a/service/service.go b/service/service.go index 09f96e9..f5dcd27 100644 --- a/service/service.go +++ b/service/service.go @@ -59,6 +59,7 @@ func (s *Service) Register(app *fiber.App) { app.Get("/accounts", s.getAccounts) app.Get("/privilege/:userId", s.getPrivilegeByUserID) app.Delete("/account/:userId", s.deleteAccountByUserID) + app.Post("/account/manualdone", s.ManualDone) // result handlers app.Post("/results/getResults/:quizId", s.GetResultsByQuizID) From f2c7ffcba04461a22062bd7d9b67802e1b57589b Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 3 Jun 2024 17:22:48 +0300 Subject: [PATCH 3/4] add full logic manual done route --- go.mod | 3 +-- go.sum | 7 ++----- openapi.yaml | 43 ++++++++++++++++++++++++++++++++++++++++++ service/account_svc.go | 10 ++++++++++ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 0adce39..8537691 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( google.golang.org/grpc v1.64.0 google.golang.org/protobuf v1.34.1 penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 - penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240520145524-451212248881 + penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240603140127-1a0489c42964 penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990 ) @@ -47,7 +47,6 @@ require ( github.com/richardlehane/msoleps v1.0.3 // indirect github.com/rivo/uniseg v0.4.7 // 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/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.53.0 // indirect diff --git a/go.sum b/go.sum index 47df28f..22b7e98 100644 --- a/go.sum +++ b/go.sum @@ -124,8 +124,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= -github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM= github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf h1:TJJm6KcBssmbWzplF5lzixXl1RBAi/ViPs1GaSOkhwo= github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf/go.mod h1:1FsorU3vnXO9xS9SrhUp8fRb/6H/Zfll0rPt1i4GWaA= github.com/twmb/franz-go v1.16.1 h1:rpWc7fB9jd7TgmCyfxzenBI+QbgS8ZfJOUQE+tzPtbE= @@ -241,7 +239,6 @@ google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFW 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 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/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -262,7 +259,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM= -penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240520145524-451212248881 h1:U1/WGQdwZsmrV/ta7Uqm13Dg07IPN/5omS8gzBJYZv4= -penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240520145524-451212248881/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240603140127-1a0489c42964 h1:I44x6hYN9nAKcZU56FaJZ8pD3S7+lwuVX/CE9KkGzww= +penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240603140127-1a0489c42964/go.mod h1:G1ZAWaQq6WW1wG9Shy57K4ZIezuhaBckQgsqQ+lhe94= penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990 h1:jiO8GWO+3sCnDAV8/NAV8tQIUwae/I6/xiDilW7zf0o= penahub.gitlab.yandexcloud.net/backend/quiz/worker.git v0.0.0-20240421230341-0e086fcbb990/go.mod h1:zswBuTwmEsFHBVRu1nkG3/Fwylk5Vcm8OUm9iWxccSE= diff --git a/openapi.yaml b/openapi.yaml index 365ccfb..4f2c543 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -1478,6 +1478,49 @@ paths: type: string '500': 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: application/json: schema: diff --git a/service/account_svc.go b/service/account_svc.go index b20e3be..7c708ba 100644 --- a/service/account_svc.go +++ b/service/account_svc.go @@ -2,9 +2,11 @@ package service import ( "database/sql" + "errors" "github.com/gofiber/fiber/v2" "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/pj_errors" "penahub.gitlab.yandexcloud.net/backend/quiz/core.git/brokers" "time" ) @@ -216,5 +218,13 @@ func (s *Service) ManualDone(ctx *fiber.Ctx) error { 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) } From f5603b818e9ee0a6fa19ee016bc5a089da11185d Mon Sep 17 00:00:00 2001 From: skeris Date: Fri, 7 Jun 2024 01:17:06 +0300 Subject: [PATCH 4/4] -- --- Dockerfile | 4 ++-- deployments/staging/docker-compose.yaml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 14fd87e..d3a769e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:alpine as build +FROM penahub.gitlab.yandexcloud.net:5050/devops/dockerhub-backup/golang as build WORKDIR /app RUN apk add git COPY . . @@ -8,7 +8,7 @@ RUN git config --global url."https://buildToken:glpat-axA8ttckx3aPf_xd2Dym@penah RUN go mod download 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/schema /schema EXPOSE 1488 diff --git a/deployments/staging/docker-compose.yaml b/deployments/staging/docker-compose.yaml index 1ef56b0..376c537 100644 --- a/deployments/staging/docker-compose.yaml +++ b/deployments/staging/docker-compose.yaml @@ -1,3 +1,4 @@ +version: "3" services: core: hostname: squiz-core