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/app/app.go b/app/app.go index b337b6b..d4cab6a 100644 --- a/app/app.go +++ b/app/app.go @@ -15,7 +15,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" @@ -62,9 +61,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"` @@ -163,7 +159,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.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{ Dal: pgdal, AuthClient: authClient, - RedirectURl: options.RedirectURL, - Encrypt: encrypt, Producer: producer, ServiceName: options.ServiceName, }) 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 diff --git a/go.mod b/go.mod index 8b7b782..55bd478 100644 --- a/go.mod +++ b/go.mod @@ -50,7 +50,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 9d61cdd..f321776 100644 --- a/go.sum +++ b/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= 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= 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 2883d5c..9eb0d7e 100644 --- a/service/account_svc.go +++ b/service/account_svc.go @@ -2,10 +2,12 @@ package service import ( "database/sql" + "errors" "github.com/gofiber/fiber/v2" "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/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/models" "time" @@ -211,3 +213,26 @@ 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") + } + + 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) +} diff --git a/service/quiz_svc.go b/service/quiz_svc.go index afef131..7cb3d15 100644 --- a/service/quiz_svc.go +++ b/service/quiz_svc.go @@ -1,7 +1,6 @@ package service import ( - "fmt" "github.com/gofiber/fiber/v2" "net/url" "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) } -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..f5dcd27 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 @@ -67,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)