add crud for rule
This commit is contained in:
parent
16a3779df5
commit
e8642a1077
2
go.mod
2
go.mod
@ -11,7 +11,7 @@ require (
|
||||
github.com/twmb/franz-go v1.16.1
|
||||
go.uber.org/zap v1.27.0
|
||||
google.golang.org/protobuf v1.33.0
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240422151612-18b9520cd3db
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240423120424-9cbe8b6b275b
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af
|
||||
)
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -153,5 +153,7 @@ penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3
|
||||
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-20240422151612-18b9520cd3db h1:wOMm1w2Fc7rLPIfDYCy3jltDxBb82V1g0sxu30iykEE=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240422151612-18b9520cd3db/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240423120424-9cbe8b6b275b h1:mVDoUMJON/WZSikdZ/i68Pt/A4K9irFhiI4diFRWL4A=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240423120424-9cbe8b6b275b/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=
|
||||
|
@ -9,15 +9,23 @@ import (
|
||||
func extractParams(ctx *fiber.Ctx) (*model.PaginationReq, error) {
|
||||
pageStr := ctx.Query("page")
|
||||
sizeStr := ctx.Query("size")
|
||||
page := 1
|
||||
size := 25
|
||||
|
||||
page, err := strconv.Atoi(pageStr)
|
||||
if err != nil {
|
||||
return nil, ctx.Status(fiber.StatusBadRequest).SendString("Invalid page parameter")
|
||||
if pageStr != "" {
|
||||
pageNew, err := strconv.Atoi(pageStr)
|
||||
if err != nil {
|
||||
return nil, ctx.Status(fiber.StatusBadRequest).SendString("Invalid page parameter")
|
||||
}
|
||||
page = pageNew
|
||||
}
|
||||
|
||||
size, err := strconv.Atoi(sizeStr)
|
||||
if err != nil {
|
||||
return nil, ctx.Status(fiber.StatusBadRequest).SendString("Invalid size parameter")
|
||||
if sizeStr != "" {
|
||||
sizeNew, err := strconv.Atoi(sizeStr)
|
||||
if err != nil {
|
||||
return nil, ctx.Status(fiber.StatusBadRequest).SendString("Invalid size parameter")
|
||||
}
|
||||
size = sizeNew
|
||||
}
|
||||
|
||||
req := model.PaginationReq{
|
||||
|
@ -2,45 +2,67 @@ package controllers
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (c *Controller) ChangeQuizSettings(ctx *fiber.Ctx) error {
|
||||
accountID, ok := middleware.GetAccountId(ctx)
|
||||
if !ok {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
quizIDInt, err := strconv.Atoi(quizID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("failed convert quizID to int")
|
||||
}
|
||||
|
||||
var request model.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.ChangeQuizSettings(ctx.Context(), &request)
|
||||
response, err := c.service.ChangeQuizSettings(ctx.Context(), &request, accountID, quizIDInt)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) SetQuizSettings(ctx *fiber.Ctx) error {
|
||||
accountID, ok := middleware.GetAccountId(ctx)
|
||||
if !ok {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
quizID := ctx.Params("quizID")
|
||||
if quizID == "" {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
quizIDInt, err := strconv.Atoi(quizID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("failed convert quizID to int")
|
||||
}
|
||||
|
||||
var request model.RulesReq
|
||||
if err := ctx.BodyParser(&request); err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
||||
}
|
||||
|
||||
err := c.service.SetQuizSettings(ctx.Context(), &request)
|
||||
response, err := c.service.SetQuizSettings(ctx.Context(), &request, accountID, quizIDInt)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) GettingQuizRules(ctx *fiber.Ctx) error {
|
||||
@ -49,7 +71,12 @@ func (c *Controller) GettingQuizRules(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("quizID is nil")
|
||||
}
|
||||
|
||||
response, err := c.service.GettingQuizRules(ctx.Context())
|
||||
quizIDInt, err := strconv.Atoi(quizID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusBadRequest).SendString("failed convert quizID to int")
|
||||
}
|
||||
|
||||
response, err := c.service.GettingQuizRules(ctx.Context(), quizIDInt)
|
||||
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
|
@ -2,32 +2,35 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
)
|
||||
|
||||
func (s *Service) ChangeQuizSettings(ctx context.Context, request *model.RulesReq) error {
|
||||
func (s *Service) ChangeQuizSettings(ctx context.Context, request *model.RulesReq, accountID string, quizID int) (*model.Rule, error) {
|
||||
|
||||
err := s.repository.AmoRepo.ChangeQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SetQuizSettings(ctx context.Context, request *model.RulesReq) error {
|
||||
|
||||
err := s.repository.AmoRepo.SetQuizSettings(ctx, request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingQuizRules(ctx context.Context) (*model.Rule, error) {
|
||||
|
||||
response, err := s.repository.AmoRepo.GettingQuizRules(ctx)
|
||||
rule, err := s.repository.AmoRepo.ChangeQuizSettings(ctx, request, accountID, quizID)
|
||||
if err != nil {
|
||||
s.logger.Error("error change quiz settings", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
return rule, nil
|
||||
}
|
||||
|
||||
func (s *Service) SetQuizSettings(ctx context.Context, request *model.RulesReq, accountID string, quizID int) (*model.Rule, error) {
|
||||
rule, err := s.repository.AmoRepo.SetQuizSettings(ctx, request, accountID, quizID)
|
||||
if err != nil {
|
||||
s.logger.Error("error setting quiz settings", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
return rule, nil
|
||||
}
|
||||
|
||||
func (s *Service) GettingQuizRules(ctx context.Context, quizID int) (*model.Rule, error) {
|
||||
|
||||
rule, err := s.repository.AmoRepo.GettingQuizRules(ctx, quizID)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting quiz settings", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
return rule, nil
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*model.
|
||||
link, err := s.socialAuthClient.GenerateAmocrmAuthURL(accountID)
|
||||
if err != nil {
|
||||
s.logger.Error("error sending request to pena social auth service:", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := model.ConnectAccountResp{
|
||||
|
39
openapi.yaml
39
openapi.yaml
@ -8,7 +8,6 @@ tags:
|
||||
- name: main
|
||||
description: Операции связанные с AmoCRM
|
||||
|
||||
|
||||
paths:
|
||||
/account:
|
||||
post:
|
||||
@ -203,6 +202,8 @@ paths:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: "#/components/schemas/UserListResp"
|
||||
'400':
|
||||
$ref: '#/components/responses/400'
|
||||
'401':
|
||||
$ref: '#/components/responses/401'
|
||||
'500':
|
||||
@ -251,6 +252,8 @@ paths:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: "#/components/schemas/UserListPipelinesResp"
|
||||
'400':
|
||||
$ref: '#/components/responses/400'
|
||||
'401':
|
||||
$ref: '#/components/responses/401'
|
||||
'500':
|
||||
@ -299,6 +302,8 @@ paths:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: "#/components/schemas/UserListStepsResp"
|
||||
'400':
|
||||
$ref: '#/components/responses/400'
|
||||
'401':
|
||||
$ref: '#/components/responses/401'
|
||||
'500':
|
||||
@ -347,6 +352,8 @@ paths:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: "#/components/schemas/UserListFieldsResp"
|
||||
'400':
|
||||
$ref: '#/components/responses/400'
|
||||
'401':
|
||||
$ref: '#/components/responses/401'
|
||||
'500':
|
||||
@ -395,6 +402,8 @@ paths:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: "#/components/schemas/UserListTagsResp"
|
||||
'400':
|
||||
$ref: '#/components/responses/400'
|
||||
'401':
|
||||
$ref: '#/components/responses/401'
|
||||
'500':
|
||||
@ -432,6 +441,10 @@ paths:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: "#/components/schemas/Rule"
|
||||
'400':
|
||||
$ref: '#/components/responses/400'
|
||||
'500':
|
||||
$ref: '#/components/responses/500'
|
||||
post:
|
||||
operationId: SetQuizSettings
|
||||
description: создание настроек интеграции для конкретного квиза
|
||||
@ -451,7 +464,17 @@ paths:
|
||||
$ref: "#/components/schemas/RulesReq"
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
description: после публикации возвращается опубликованное правило
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: "#/components/schemas/Rule"
|
||||
'400':
|
||||
$ref: '#/components/responses/400'
|
||||
'401':
|
||||
$ref: '#/components/responses/401'
|
||||
'500':
|
||||
$ref: '#/components/responses/500'
|
||||
patch:
|
||||
operationId: ChangeQuizSettings
|
||||
description: изменение настроек интеграции для конкретного квиза
|
||||
@ -471,7 +494,17 @@ paths:
|
||||
$ref: "#/components/schemas/RulesReq"
|
||||
responses:
|
||||
'200':
|
||||
description: Success
|
||||
description: после изменения возвращается измененное правило
|
||||
content:
|
||||
'application/json':
|
||||
schema:
|
||||
$ref: "#/components/schemas/Rule"
|
||||
'400':
|
||||
$ref: '#/components/responses/400'
|
||||
'401':
|
||||
$ref: '#/components/responses/401'
|
||||
'500':
|
||||
$ref: '#/components/responses/500'
|
||||
|
||||
components:
|
||||
schemas:
|
||||
|
Loading…
Reference in New Issue
Block a user