MSP-5013 Add variables swagger
This commit is contained in:
1 parent
148327c74e
commit
be0dea3702
7 files changed
+397
-20
No files matched your search
@@ -153,12 +153,12 @@ func (c Config) CreateUpdateConfig(
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ConfigIdRequest true "id конфигурации"
|
||||
// @Param body body domain.IdRequest true "id конфигурации"
|
||||
// @Success 200 {object} domain.Config
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2002` - конфиг не найден<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/get_config_by_id [POST]
|
||||
func (c Config) GetConfigById(ctx context.Context, req domain.ConfigIdRequest) (*domain.Config, error) {
|
||||
func (c Config) GetConfigById(ctx context.Context, req domain.IdRequest) (*domain.Config, error) {
|
||||
config, err := c.service.GetConfigById(ctx, req.Id)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrConfigNotFound):
|
||||
@@ -180,12 +180,12 @@ func (c Config) GetConfigById(ctx context.Context, req domain.ConfigIdRequest) (
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ConfigIdRequest true "id конфигурации для изменения"
|
||||
// @Param body body domain.IdRequest true "id конфигурации для изменения"
|
||||
// @Success 200
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2002` - конфиг не найден<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/mark_config_as_active [POST]
|
||||
func (c Config) MarkConfigAsActive(ctx context.Context, identity domain.ConfigIdRequest) error {
|
||||
func (c Config) MarkConfigAsActive(ctx context.Context, identity domain.IdRequest) error {
|
||||
err := c.service.MarkConfigAsActive(ctx, identity.Id)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrConfigNotFound):
|
||||
|
||||
@@ -28,12 +28,12 @@ func NewConfigHistory(service ConfigHistoryService) ConfigHistory {
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ConfigIdRequest true "id конфигурации"
|
||||
// @Param body body domain.IdRequest true "id конфигурации"
|
||||
// @Success 200 {array} domain.ConfigVersion
|
||||
// @Failure 400 {object} apierrors.Error "если не указан массив идентификаторов"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/get_all_version [POST]
|
||||
func (c ConfigHistory) GetAllVersion(ctx context.Context, req domain.ConfigIdRequest) ([]domain.ConfigVersion, error) {
|
||||
func (c ConfigHistory) GetAllVersion(ctx context.Context, req domain.IdRequest) ([]domain.ConfigVersion, error) {
|
||||
versions, err := c.service.GetAllVersions(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
@@ -47,12 +47,12 @@ func (c ConfigHistory) GetAllVersion(ctx context.Context, req domain.ConfigIdReq
|
||||
// @Tags Конфигурация
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ConfigIdRequest true "id версии конфигурации"
|
||||
// @Param body body domain.IdRequest true "id версии конфигурации"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} apierrors.Error "не указан массив идентификаторов"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /config/delete_version [POST]
|
||||
func (c ConfigHistory) DeleteConfigVersion(ctx context.Context, req domain.ConfigIdRequest) (*domain.DeleteResponse, error) {
|
||||
func (c ConfigHistory) DeleteConfigVersion(ctx context.Context, req domain.IdRequest) (*domain.DeleteResponse, error) {
|
||||
err := c.service.Delete(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
_ "github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"isp-config-service/domain"
|
||||
)
|
||||
|
||||
type Variable struct {
|
||||
}
|
||||
|
||||
// All
|
||||
// @Summary Метод получения списка всех переменных
|
||||
// @Tags Переменные
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.Variable
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/all [POST]
|
||||
func (c Variable) All(ctx context.Context) ([]domain.Variable, error) {
|
||||
|
||||
}
|
||||
|
||||
// GetByName
|
||||
// @Summary Метод получения переменной по точному совпадению имени
|
||||
// @Tags Переменные
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.VariableByNameRequest true "тело запроса"
|
||||
// @Success 200 {object} domain.Variable
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2006` - переменная по имени не найдена<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/get_by_name [POST]
|
||||
func (c Variable) GetByName(ctx context.Context, req domain.VariableByNameRequest) (*domain.Variable, error) {
|
||||
|
||||
}
|
||||
|
||||
// Create
|
||||
// @Summary Метод создания новой переменной
|
||||
// @Description Создает новую переменную с указанным наименованием и значением
|
||||
// @Tags Переменные
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.CreateVariableRequest true "тело запроса"
|
||||
// @Success 200 {object} domain.Variable
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2007` - переменная с таким именем уже существует<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/create [POST]
|
||||
func (c Variable) Create(ctx context.Context, req domain.CreateVariableRequest) (*domain.Variable, error) {
|
||||
|
||||
}
|
||||
|
||||
// Update
|
||||
// @Summary Метод обновления переменной
|
||||
// @Description Выполняет обновление переменной по ее названию
|
||||
// @Tags Переменные
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.UpdateVariableRequest true "тело запроса"
|
||||
// @Success 200 {object} domain.Variable
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/update [POST]
|
||||
func (c Variable) Update(ctx context.Context, req domain.UpdateVariableRequest) (*domain.Variable, error) {
|
||||
|
||||
}
|
||||
|
||||
// Upsert
|
||||
// @Summary Метод добавления/обновления переменных
|
||||
// @Description Выполняет безусловное добавление/обновление указанных в теле запроса переменных
|
||||
// @Description Операция выполняется не в транзакции
|
||||
// @Tags Переменные
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []domain.UpsertVariableRequest true "тело запроса"
|
||||
// @Success 200
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/upsert [POST]
|
||||
func (c Variable) Upsert(ctx context.Context, req []domain.UpsertVariableRequest) error {
|
||||
|
||||
}
|
||||
|
||||
// Delete
|
||||
// @Summary Метод удаления переменной
|
||||
// @Description Переменная связанная с конфигурациями, не может быть удалена
|
||||
// @Tags Переменные
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.VariableByNameRequest true "тело запроса"
|
||||
// @Success 200
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2006` - переменная по имени не найдена<br/>`errorCode: 2008` - переменная используется в конфигурациях<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/delete [POST]
|
||||
func (c Variable) Delete(ctx context.Context, req domain.VariableByNameRequest) (*domain.Variable, error) {
|
||||
|
||||
}
|
||||
+248
-11
@@ -28,13 +28,6 @@ definitions:
|
||||
version:
|
||||
type: integer
|
||||
type: object
|
||||
domain.ConfigIdRequest:
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
type: object
|
||||
domain.ConfigSchema:
|
||||
properties:
|
||||
createdAt:
|
||||
@@ -100,6 +93,21 @@ definitions:
|
||||
- moduleId
|
||||
- name
|
||||
type: object
|
||||
domain.CreateVariableRequest:
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
value:
|
||||
type: string
|
||||
required:
|
||||
- name
|
||||
- type
|
||||
- value
|
||||
type: object
|
||||
domain.DeleteResponse:
|
||||
properties:
|
||||
deleted:
|
||||
@@ -126,6 +134,20 @@ definitions:
|
||||
required:
|
||||
- moduleName
|
||||
type: object
|
||||
domain.IdRequest:
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
required:
|
||||
- id
|
||||
type: object
|
||||
domain.LinkedConfig:
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
type: object
|
||||
domain.ModuleInfo:
|
||||
properties:
|
||||
active:
|
||||
@@ -147,6 +169,59 @@ definitions:
|
||||
$ref: '#/definitions/domain.Connection'
|
||||
type: array
|
||||
type: object
|
||||
domain.UpdateVariableRequest:
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
value:
|
||||
type: string
|
||||
required:
|
||||
- name
|
||||
- value
|
||||
type: object
|
||||
domain.UpsertVariableRequest:
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
value:
|
||||
type: string
|
||||
required:
|
||||
- description
|
||||
- name
|
||||
- value
|
||||
type: object
|
||||
domain.Variable:
|
||||
properties:
|
||||
containsInConfigs:
|
||||
items:
|
||||
$ref: '#/definitions/domain.LinkedConfig'
|
||||
type: array
|
||||
createdAt:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
updatedAt:
|
||||
type: string
|
||||
value:
|
||||
type: string
|
||||
type: object
|
||||
domain.VariableByNameRequest:
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
required:
|
||||
- name
|
||||
type: object
|
||||
github_com_txix-open_isp-kit_grpc_apierrors.Error:
|
||||
properties:
|
||||
details:
|
||||
@@ -243,7 +318,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigIdRequest'
|
||||
$ref: '#/definitions/domain.IdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@@ -304,7 +379,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigIdRequest'
|
||||
$ref: '#/definitions/domain.IdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@@ -335,7 +410,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigIdRequest'
|
||||
$ref: '#/definitions/domain.IdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@@ -398,7 +473,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.ConfigIdRequest'
|
||||
$ref: '#/definitions/domain.IdRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
@@ -516,4 +591,166 @@ paths:
|
||||
summary: Метод получения схемы конфигурации модуля
|
||||
tags:
|
||||
- Схема
|
||||
/variable/all:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.Variable'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод получения списка всех переменных
|
||||
tags:
|
||||
- Переменные
|
||||
/variable/create:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Создает новую переменную с указанным наименованием и значением
|
||||
parameters:
|
||||
- description: тело запроса
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.CreateVariableRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.Variable'
|
||||
"400":
|
||||
description: '`errorCode: 2007` - переменная с таким именем уже существует<br/>'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод создания новой переменной
|
||||
tags:
|
||||
- Переменные
|
||||
/variable/delete:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Переменная связанная с конфигурациями, не может быть удалена
|
||||
parameters:
|
||||
- description: тело запроса
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.VariableByNameRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
"400":
|
||||
description: '`errorCode: 2006` - переменная по имени не найдена<br/>`errorCode:
|
||||
2008` - переменная используется в конфигурациях<br/>'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод удаления переменной
|
||||
tags:
|
||||
- Переменные
|
||||
/variable/get_by_name:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: тело запроса
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.VariableByNameRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.Variable'
|
||||
"400":
|
||||
description: '`errorCode: 2006` - переменная по имени не найдена<br/>'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод получения переменной по точному совпадению имени
|
||||
tags:
|
||||
- Переменные
|
||||
/variable/update:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Выполняет обновление переменной по ее названию
|
||||
parameters:
|
||||
- description: тело запроса
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/domain.UpdateVariableRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.Variable'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод обновления переменной
|
||||
tags:
|
||||
- Переменные
|
||||
/variable/upsert:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: |-
|
||||
Выполняет безусловное добавление/обновление указанных в теле запроса переменных
|
||||
Операция выполняется не в транзакции
|
||||
parameters:
|
||||
- description: тело запроса
|
||||
in: body
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/domain.UpsertVariableRequest'
|
||||
type: array
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
summary: Метод добавления/обновления переменных
|
||||
tags:
|
||||
- Переменные
|
||||
swagger: "2.0"
|
||||
@@ -12,6 +12,9 @@ const (
|
||||
ErrorCodeInvalidConfig = 2003
|
||||
ErrorCodeConfigVersionConflict = 2004
|
||||
ErrorCodeSchemaNotFound = 2005
|
||||
ErrorCodeVariableNotFound = 2006
|
||||
ErrorCodeVariableAlreadyExists = 2007
|
||||
ErrorCodeVariableUsedInConfigs = 2008
|
||||
)
|
||||
|
||||
type ConfigValidationError struct {
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/txix-open/isp-kit/json"
|
||||
)
|
||||
|
||||
type ConfigIdRequest struct {
|
||||
type IdRequest struct {
|
||||
Id string `validate:"required"`
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package domain
|
||||
|
||||
import "time"
|
||||
|
||||
type Variable struct {
|
||||
Id string
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
Value string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
ContainsInConfigs []LinkedConfig
|
||||
}
|
||||
|
||||
type LinkedConfig struct {
|
||||
Id string
|
||||
Name string
|
||||
}
|
||||
|
||||
type CreateVariableRequest struct {
|
||||
Name string `validate:"required"`
|
||||
Description string
|
||||
Type string `validate:"required"`
|
||||
Value string `validate:"required"`
|
||||
}
|
||||
|
||||
type UpdateVariableRequest struct {
|
||||
Name string `validate:"required"`
|
||||
Description string
|
||||
Value string `validate:"required"`
|
||||
}
|
||||
|
||||
type UpsertVariableRequest struct {
|
||||
Name string `validate:"required"`
|
||||
Description string `validate:"required"`
|
||||
Value string `validate:"required"`
|
||||
}
|
||||
|
||||
type VariableByNameRequest struct {
|
||||
Name string `validate:"required"`
|
||||
}
|
||||
Reference in new issue
Block a user