MSP-5223 update response CreateUpdateConfig: add IsChanged field
This commit is contained in:
1 parent
28be68322c
commit
3c19a8d532
4 files changed
+30
-18
No files matched your search
@@ -16,7 +16,7 @@ import (
|
|||||||
type ConfigService interface {
|
type ConfigService interface {
|
||||||
GetActiveConfigByModuleName(ctx context.Context, moduleName string) (*domain.Config, error)
|
GetActiveConfigByModuleName(ctx context.Context, moduleName string) (*domain.Config, error)
|
||||||
GetConfigsByModuleId(ctx context.Context, moduleId string) ([]domain.Config, error)
|
GetConfigsByModuleId(ctx context.Context, moduleId string) ([]domain.Config, error)
|
||||||
CreateUpdateConfig(ctx context.Context, adminId int, req domain.CreateUpdateConfigRequest) (*domain.Config, error)
|
CreateUpdateConfig(ctx context.Context, adminId int, req domain.CreateUpdateConfigRequest) (*domain.CreateUpdateConfigResponse, error)
|
||||||
GetConfigById(ctx context.Context, configId string) (*domain.Config, error)
|
GetConfigById(ctx context.Context, configId string) (*domain.Config, error)
|
||||||
MarkConfigAsActive(ctx context.Context, configId string) error
|
MarkConfigAsActive(ctx context.Context, configId string) error
|
||||||
DeleteConfig(ctx context.Context, id string) error
|
DeleteConfig(ctx context.Context, id string) error
|
||||||
@@ -96,7 +96,7 @@ func (c Config) GetConfigsByModuleId(ctx context.Context, req domain.GetByModule
|
|||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param body body domain.CreateUpdateConfigRequest true "объект для сохранения"
|
// @Param body body domain.CreateUpdateConfigRequest true "объект для сохранения"
|
||||||
// @Success 200 {object} domain.Config
|
// @Success 200 {object} domain.CreateUpdateConfigResponse
|
||||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2003` - конфиг не соотвествует текущей схеме<br/>`errorCode: 2002` - указанного id не сущесвует<br/>`errorCode: 2004` - кто-то уже обновил конфигурацию<br/>`errorCode: 2005` - схема конфигурации не найдена<br/>"
|
// @Failure 400 {object} apierrors.Error "`errorCode: 2003` - конфиг не соотвествует текущей схеме<br/>`errorCode: 2002` - указанного id не сущесвует<br/>`errorCode: 2004` - кто-то уже обновил конфигурацию<br/>`errorCode: 2005` - схема конфигурации не найдена<br/>"
|
||||||
// @Failure 500 {object} apierrors.Error
|
// @Failure 500 {object} apierrors.Error
|
||||||
// @Router /config/create_update_config [POST]
|
// @Router /config/create_update_config [POST]
|
||||||
@@ -104,14 +104,14 @@ func (c Config) CreateUpdateConfig(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
authData grpc.AuthData,
|
authData grpc.AuthData,
|
||||||
req domain.CreateUpdateConfigRequest,
|
req domain.CreateUpdateConfigRequest,
|
||||||
) (*domain.Config, error) {
|
) (*domain.CreateUpdateConfigResponse, error) {
|
||||||
adminIdValue, _ := grpc.StringFromMd("x-admin-id", metadata.MD(authData))
|
adminIdValue, _ := grpc.StringFromMd("x-admin-id", metadata.MD(authData))
|
||||||
var adminId int
|
var adminId int
|
||||||
if adminIdValue != "" {
|
if adminIdValue != "" {
|
||||||
adminId, _ = strconv.Atoi(adminIdValue)
|
adminId, _ = strconv.Atoi(adminIdValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := c.service.CreateUpdateConfig(ctx, adminId, req)
|
resp, err := c.service.CreateUpdateConfig(ctx, adminId, req)
|
||||||
|
|
||||||
var validationError domain.ConfigValidationError
|
var validationError domain.ConfigValidationError
|
||||||
switch {
|
switch {
|
||||||
@@ -146,7 +146,7 @@ func (c Config) CreateUpdateConfig(
|
|||||||
case err != nil:
|
case err != nil:
|
||||||
return nil, apierrors.NewInternalServiceError(err)
|
return nil, apierrors.NewInternalServiceError(err)
|
||||||
default:
|
default:
|
||||||
return config, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -93,6 +93,13 @@ definitions:
|
|||||||
- moduleId
|
- moduleId
|
||||||
- name
|
- name
|
||||||
type: object
|
type: object
|
||||||
|
domain.CreateUpdateConfigResponse:
|
||||||
|
properties:
|
||||||
|
config:
|
||||||
|
$ref: '#/definitions/domain.Config'
|
||||||
|
isChanged:
|
||||||
|
type: boolean
|
||||||
|
type: object
|
||||||
domain.CreateVariableRequest:
|
domain.CreateVariableRequest:
|
||||||
properties:
|
properties:
|
||||||
description:
|
description:
|
||||||
@@ -286,7 +293,7 @@ paths:
|
|||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.Config'
|
$ref: '#/definitions/domain.CreateUpdateConfigResponse'
|
||||||
"400":
|
"400":
|
||||||
description: '`errorCode: 2003` - конфиг не соотвествует текущей схеме<br/>`errorCode:
|
description: '`errorCode: 2003` - конфиг не соотвествует текущей схеме<br/>`errorCode:
|
||||||
2002` - указанного id не сущесвует<br/>`errorCode: 2004` - кто-то уже
|
2002` - указанного id не сущесвует<br/>`errorCode: 2004` - кто-то уже
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ type DeleteResponse struct {
|
|||||||
Deleted int
|
Deleted int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreateUpdateConfigResponse struct {
|
||||||
|
IsChanged bool
|
||||||
|
Config Config
|
||||||
|
}
|
||||||
|
|
||||||
type ModuleInfo struct {
|
type ModuleInfo struct {
|
||||||
Id string
|
Id string
|
||||||
Name string
|
Name string
|
||||||
|
|||||||
+12
-12
@@ -121,7 +121,7 @@ func (c Config) CreateUpdateConfig(
|
|||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
adminId int,
|
adminId int,
|
||||||
req domain.CreateUpdateConfigRequest,
|
req domain.CreateUpdateConfigRequest,
|
||||||
) (*domain.Config, error) {
|
) (*domain.CreateUpdateConfigResponse, error) {
|
||||||
if !req.Unsafe {
|
if !req.Unsafe {
|
||||||
err := c.validateConfigUpdate(ctx, req.ModuleId, req.Data)
|
err := c.validateConfigUpdate(ctx, req.ModuleId, req.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -130,7 +130,9 @@ func (c Config) CreateUpdateConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if req.Id == "" {
|
if req.Id == "" {
|
||||||
return c.insertNewConfig(ctx, adminId, req)
|
newConfig, err := c.insertNewConfig(ctx, adminId, req)
|
||||||
|
return &domain.CreateUpdateConfigResponse{
|
||||||
|
Config: newConfig, IsChanged: true}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
variableExtractionResult, err := c.extractAndCheckVariables(ctx, req.Id, req.Data)
|
variableExtractionResult, err := c.extractAndCheckVariables(ctx, req.Id, req.Data)
|
||||||
@@ -152,8 +154,7 @@ func (c Config) CreateUpdateConfig(
|
|||||||
}
|
}
|
||||||
if isMatch {
|
if isMatch {
|
||||||
c.logger.Info(ctx, "no changes in config; skip update")
|
c.logger.Info(ctx, "no changes in config; skip update")
|
||||||
result := configToDto(*oldConfig, nil)
|
return &domain.CreateUpdateConfigResponse{Config: configToDto(*oldConfig, nil), IsChanged: false}, nil
|
||||||
return &result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config := entity.Config{
|
config := entity.Config{
|
||||||
@@ -175,7 +176,6 @@ func (c Config) CreateUpdateConfig(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "change config history")
|
return nil, errors.WithMessage(err, "change config history")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.variableService.SaveVariableLinks(ctx, config.Id, variableExtractionResult.VariableLinks)
|
err = c.variableService.SaveVariableLinks(ctx, config.Id, variableExtractionResult.VariableLinks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "save variable links")
|
return nil, errors.WithMessage(err, "save variable links")
|
||||||
@@ -196,8 +196,8 @@ func (c Config) CreateUpdateConfig(
|
|||||||
Version: req.Version + 1,
|
Version: req.Version + 1,
|
||||||
Active: oldConfig.Active,
|
Active: oldConfig.Active,
|
||||||
}
|
}
|
||||||
result := configToDto(newConfig, nil)
|
return &domain.CreateUpdateConfigResponse{
|
||||||
return &result, nil
|
Config: configToDto(newConfig, nil), IsChanged: true}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) GetConfigById(ctx context.Context, configId string) (*domain.Config, error) {
|
func (c Config) GetConfigById(ctx context.Context, configId string) (*domain.Config, error) {
|
||||||
@@ -287,7 +287,7 @@ func (c Config) SyncConfig(ctx context.Context, moduleName string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) insertNewConfig(ctx context.Context, adminId int, req domain.CreateUpdateConfigRequest) (*domain.Config, error) {
|
func (c Config) insertNewConfig(ctx context.Context, adminId int, req domain.CreateUpdateConfigRequest) (domain.Config, error) {
|
||||||
config := entity.Config{
|
config := entity.Config{
|
||||||
Id: uuid.NewString(),
|
Id: uuid.NewString(),
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
@@ -299,20 +299,20 @@ func (c Config) insertNewConfig(ctx context.Context, adminId int, req domain.Cre
|
|||||||
}
|
}
|
||||||
err := c.configRepo.Insert(ctx, config)
|
err := c.configRepo.Insert(ctx, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "insert new config")
|
return domain.Config{}, errors.WithMessage(err, "insert new config")
|
||||||
}
|
}
|
||||||
|
|
||||||
extractResult, err := c.extractAndCheckVariables(ctx, config.Id, config.Data)
|
extractResult, err := c.extractAndCheckVariables(ctx, config.Id, config.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return domain.Config{}, err
|
||||||
}
|
}
|
||||||
err = c.variableService.SaveVariableLinks(ctx, config.Id, extractResult.VariableLinks)
|
err = c.variableService.SaveVariableLinks(ctx, config.Id, extractResult.VariableLinks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "save variable links")
|
return domain.Config{}, errors.WithMessage(err, "save variable links")
|
||||||
}
|
}
|
||||||
|
|
||||||
result := configToDto(config, nil)
|
result := configToDto(config, nil)
|
||||||
return &result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) extractAndCheckVariables(ctx context.Context, configId string, input []byte) (*domain.VariableExtractionResult, error) {
|
func (c Config) extractAndCheckVariables(ctx context.Context, configId string, input []byte) (*domain.VariableExtractionResult, error) {
|
||||||
|
|||||||
Reference in new issue
Block a user