diff --git a/controller/api/config.go b/controller/api/config.go index b66d665..ed027c6 100644 --- a/controller/api/config.go +++ b/controller/api/config.go @@ -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` - конфиг не найден
" // @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` - конфиг не найден
" // @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): diff --git a/controller/api/config_history.go b/controller/api/config_history.go index 844bccd..0ec56cf 100644 --- a/controller/api/config_history.go +++ b/controller/api/config_history.go @@ -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) diff --git a/controller/api/variable.go b/controller/api/variable.go new file mode 100644 index 0000000..b1197d1 --- /dev/null +++ b/controller/api/variable.go @@ -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` - переменная по имени не найдена
" +// @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` - переменная с таким именем уже существует
" +// @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` - переменная по имени не найдена
`errorCode: 2008` - переменная используется в конфигурациях
" +// @Failure 500 {object} apierrors.Error +// @Router /variable/delete [POST] +func (c Variable) Delete(ctx context.Context, req domain.VariableByNameRequest) (*domain.Variable, error) { + +} diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 45581b8..cbf5414 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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` - переменная с таким именем уже существует
' + 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` - переменная по имени не найдена
`errorCode: + 2008` - переменная используется в конфигурациях
' + 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` - переменная по имени не найдена
' + 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" diff --git a/domain/errors.go b/domain/errors.go index ab2e4ae..6e1fbd6 100644 --- a/domain/errors.go +++ b/domain/errors.go @@ -12,6 +12,9 @@ const ( ErrorCodeInvalidConfig = 2003 ErrorCodeConfigVersionConflict = 2004 ErrorCodeSchemaNotFound = 2005 + ErrorCodeVariableNotFound = 2006 + ErrorCodeVariableAlreadyExists = 2007 + ErrorCodeVariableUsedInConfigs = 2008 ) type ConfigValidationError struct { diff --git a/domain/request.go b/domain/request.go index 65cb20b..0cdf9b4 100644 --- a/domain/request.go +++ b/domain/request.go @@ -4,7 +4,7 @@ import ( "github.com/txix-open/isp-kit/json" ) -type ConfigIdRequest struct { +type IdRequest struct { Id string `validate:"required"` } diff --git a/domain/variable.go b/domain/variable.go new file mode 100644 index 0000000..1b1d289 --- /dev/null +++ b/domain/variable.go @@ -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"` +}