From 418c4e757fa1ddec10ed5548f5e0d6a971b4d352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 20 Mar 2025 19:00:58 +0300 Subject: [PATCH] MSP-5014 Rename entity to model --- command/utils/config.go | 4 ++-- command/vars.go | 14 ++++++------ {entity => model}/config.go | 2 +- {entity => model}/variable.go | 2 +- repository/config.go | 42 +++++++++++++++++------------------ service/config.go | 22 +++++++++--------- 6 files changed, 43 insertions(+), 43 deletions(-) rename {entity => model}/config.go (98%) rename {entity => model}/variable.go (98%) diff --git a/command/utils/config.go b/command/utils/config.go index 038160c..f509f65 100644 --- a/command/utils/config.go +++ b/command/utils/config.go @@ -1,11 +1,11 @@ package utils import ( - "ispctl/entity" + "ispctl/model" "ispctl/service" ) -func CreateUpdateConfig(stringToChange string, configuration *entity.Config) error { +func CreateUpdateConfig(stringToChange string, configuration *model.Config) error { answer, err := service.Config.CreateUpdateConfig(stringToChange, configuration) if err != nil { return err diff --git a/command/vars.go b/command/vars.go index b7e5336..2c12557 100644 --- a/command/vars.go +++ b/command/vars.go @@ -6,7 +6,7 @@ import ( "ispctl/bash" "ispctl/command/flag" "ispctl/command/utils" - "ispctl/entity" + "ispctl/model" "ispctl/service" "os" "strings" @@ -97,11 +97,11 @@ func (g varsCommands) getByName(ctx *cli.Context) error { func (g varsCommands) set(ctx *cli.Context) error { variableName := ctx.Args().Get(0) variableValue := ctx.Args().Get(1) - variableType := entity.TextVariableType + variableType := model.TextVariableType if ctx.Bool(flag.SetVariableSecretType.Name) { - variableType = entity.SecretVariableType + variableType = model.SecretVariableType } - return service.Config.UpsertVariables([]entity.UpsertVariableRequest{{ + return service.Config.UpsertVariables([]model.UpsertVariableRequest{{ Name: variableName, Value: variableValue, Type: variableType, @@ -120,7 +120,7 @@ func (g varsCommands) upload(ctx *cli.Context) error { return service.Config.UpsertVariables(variables) } -func (g varsCommands) readVariablesFromCsv(filepath string) ([]entity.UpsertVariableRequest, error) { +func (g varsCommands) readVariablesFromCsv(filepath string) ([]model.UpsertVariableRequest, error) { file, err := os.Open(filepath) if err != nil { return nil, fmt.Errorf("failed to open file %s: %w", filepath, err) @@ -140,9 +140,9 @@ func (g varsCommands) readVariablesFromCsv(filepath string) ([]entity.UpsertVari for i, col := range header { columnIndexes[strings.ToLower(col)] = i } - variables := make([]entity.UpsertVariableRequest, 0, len(records)-1) + variables := make([]model.UpsertVariableRequest, 0, len(records)-1) for _, row := range records[1:] { - variables = append(variables, entity.UpsertVariableRequest{ + variables = append(variables, model.UpsertVariableRequest{ Name: row[columnIndexes["name"]], Type: row[columnIndexes["type"]], Value: row[columnIndexes["value"]], diff --git a/entity/config.go b/model/config.go similarity index 98% rename from entity/config.go rename to model/config.go index dfe60b7..8c33d14 100644 --- a/entity/config.go +++ b/model/config.go @@ -1,4 +1,4 @@ -package entity +package model import ( "time" diff --git a/entity/variable.go b/model/variable.go similarity index 98% rename from entity/variable.go rename to model/variable.go index be6fd5f..c3bba3f 100644 --- a/entity/variable.go +++ b/model/variable.go @@ -1,4 +1,4 @@ -package entity +package model import "github.com/pkg/errors" diff --git a/repository/config.go b/repository/config.go index 7fcf2a2..ef0db9a 100644 --- a/repository/config.go +++ b/repository/config.go @@ -4,7 +4,7 @@ import ( "context" "fmt" epb "google.golang.org/genproto/googleapis/rpc/errdetails" - "ispctl/entity" + "ispctl/model" "strings" "time" @@ -39,8 +39,8 @@ func NewConfig(cli *client.Client) Config { } } -func (c Config) GetAvailableConfigs() ([]entity.ModuleInfo, error) { - response := make([]entity.ModuleInfo, 0) +func (c Config) GetAvailableConfigs() ([]model.ModuleInfo, error) { + response := make([]model.ModuleInfo, 0) err := c.cli.Invoke(getAvailableConfigs). JsonResponseBody(&response). Timeout(time.Second). @@ -51,9 +51,9 @@ func (c Config) GetAvailableConfigs() ([]entity.ModuleInfo, error) { return response, nil } -func (c Config) GetConfigByModuleName(name string) (*entity.Config, error) { - request := &entity.GetModuleByUuidAndNameRequest{ModuleName: name} - response := new(entity.Config) +func (c Config) GetConfigByModuleName(name string) (*model.Config, error) { + request := &model.GetModuleByUuidAndNameRequest{ModuleName: name} + response := new(model.Config) err := c.cli.Invoke(getConfigByModuleName). JsonRequestBody(request). JsonResponseBody(&response). @@ -61,7 +61,7 @@ func (c Config) GetConfigByModuleName(name string) (*entity.Config, error) { Do(c.baseCtx) switch { case status.Code(err) == codes.NotFound: - return nil, entity.ErrModuleNotFound + return nil, model.ErrModuleNotFound case err != nil: return nil, errors.WithMessagef(err, "call %s", getConfigByModuleName) default: @@ -69,8 +69,8 @@ func (c Config) GetConfigByModuleName(name string) (*entity.Config, error) { } } -func (c Config) CreateUpdateConfig(request entity.Config) (*entity.Config, error) { - response := new(entity.Config) +func (c Config) CreateUpdateConfig(request model.Config) (*model.Config, error) { + response := new(model.Config) err := c.cli.Invoke(createUpdateConfig). JsonRequestBody(request). JsonResponseBody(&response). @@ -82,9 +82,9 @@ func (c Config) CreateUpdateConfig(request entity.Config) (*entity.Config, error return response, nil } -func (c Config) GetSchemaByModuleId(moduleId string) (*entity.ConfigSchema, error) { - request := entity.GetSchemaByModuleIdRequest{ModuleId: moduleId} - response := new(entity.ConfigSchema) +func (c Config) GetSchemaByModuleId(moduleId string) (*model.ConfigSchema, error) { + request := model.GetSchemaByModuleIdRequest{ModuleId: moduleId} + response := new(model.ConfigSchema) err := c.cli.Invoke(getSchemaByModuleId). JsonRequestBody(request). JsonResponseBody(&response). @@ -96,8 +96,8 @@ func (c Config) GetSchemaByModuleId(moduleId string) (*entity.ConfigSchema, erro return response, nil } -func (c Config) GetAllVariables() ([]entity.Variable, error) { - response := make([]entity.Variable, 0) +func (c Config) GetAllVariables() ([]model.Variable, error) { + response := make([]model.Variable, 0) err := c.cli.Invoke(getAllVariables). JsonResponseBody(&response). Timeout(time.Second). @@ -108,9 +108,9 @@ func (c Config) GetAllVariables() ([]entity.Variable, error) { return response, nil } -func (c Config) GetVariableByName(variableName string) (*entity.Variable, error) { - request := entity.VariableByNameRequest{Name: variableName} - response := new(entity.Variable) +func (c Config) GetVariableByName(variableName string) (*model.Variable, error) { + request := model.VariableByNameRequest{Name: variableName} + response := new(model.Variable) err := c.cli.Invoke(getVariableByName). JsonRequestBody(request). JsonResponseBody(&response). @@ -122,7 +122,7 @@ func (c Config) GetVariableByName(variableName string) (*entity.Variable, error) return response, nil } -func (c Config) UpsertVariables(request []entity.UpsertVariableRequest) error { +func (c Config) UpsertVariables(request []model.UpsertVariableRequest) error { err := c.cli.Invoke(upsertVariable). JsonRequestBody(request). Timeout(time.Second). @@ -134,7 +134,7 @@ func (c Config) UpsertVariables(request []entity.UpsertVariableRequest) error { } func (c Config) DeleteVariable(variableName string) error { - request := entity.VariableByNameRequest{Name: variableName} + request := model.VariableByNameRequest{Name: variableName} err := c.cli.Invoke(deleteVariable). JsonRequestBody(request). Timeout(time.Second). @@ -151,8 +151,8 @@ func (c Config) handleVariableError(err error, endpoint string) error { return errors.WithMessagef(err, "call %s", endpoint) } switch { - case apiError.ErrorCode == entity.ErrCodeVariableNotFound: - return entity.ErrVariableNotFound + case apiError.ErrorCode == model.ErrCodeVariableNotFound: + return model.ErrVariableNotFound default: return errors.WithMessagef(err, "call %s", endpoint) } diff --git a/service/config.go b/service/config.go index 1eb716a..3bb92ec 100644 --- a/service/config.go +++ b/service/config.go @@ -3,7 +3,7 @@ package service import ( "encoding/json" - "ispctl/entity" + "ispctl/model" "ispctl/repository" "github.com/pkg/errors" @@ -26,18 +26,18 @@ func (c *ConfigService) ReceiveConfiguration(host string) error { return nil } -func (c *ConfigService) GetAvailableConfigs() ([]entity.ModuleInfo, error) { +func (c *ConfigService) GetAvailableConfigs() ([]model.ModuleInfo, error) { return c.configRepo.GetAvailableConfigs() } -func (c *ConfigService) GetConfigurationByModuleName(moduleName string) (*entity.Config, error) { +func (c *ConfigService) GetConfigurationByModuleName(moduleName string) (*model.Config, error) { if moduleName == "" { return nil, errors.New("need module name") } moduleConfiguration, err := c.configRepo.GetConfigByModuleName(moduleName) switch { - case errors.Is(err, entity.ErrModuleNotFound): + case errors.Is(err, model.ErrModuleNotFound): return nil, errors.Errorf("module [%s] not found", moduleName) default: return moduleConfiguration, err @@ -52,7 +52,7 @@ func (c *ConfigService) GetSchemaByModuleId(moduleId string) (schema.Schema, err return configSchema.Schema, nil } -func (c *ConfigService) CreateUpdateConfig(stringToChange string, configuration *entity.Config) (map[string]any, error) { +func (c *ConfigService) CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error) { newData := make(map[string]any) if stringToChange != "" { err := json.Unmarshal([]byte(stringToChange), &newData) @@ -65,7 +65,7 @@ func (c *ConfigService) CreateUpdateConfig(stringToChange string, configuration return c.CreateUpdateConfigV2(configuration) } -func (c *ConfigService) CreateUpdateConfigV2(configuration *entity.Config) (map[string]any, error) { +func (c *ConfigService) CreateUpdateConfigV2(configuration *model.Config) (map[string]any, error) { configuration.Unsafe = c.UnsafeEnable resp, err := c.configRepo.CreateUpdateConfig(*configuration) if err != nil { @@ -74,18 +74,18 @@ func (c *ConfigService) CreateUpdateConfigV2(configuration *entity.Config) (map[ return resp.Data, nil } -func (c *ConfigService) GetAllVariables() ([]entity.Variable, error) { +func (c *ConfigService) GetAllVariables() ([]model.Variable, error) { return c.configRepo.GetAllVariables() } -func (c *ConfigService) GetVariableByName(variableName string) (*entity.Variable, error) { +func (c *ConfigService) GetVariableByName(variableName string) (*model.Variable, error) { if variableName == "" { return nil, errors.New("need variable name") } variable, err := c.configRepo.GetVariableByName(variableName) switch { - case errors.Is(err, entity.ErrVariableNotFound): + case errors.Is(err, model.ErrVariableNotFound): return nil, errors.Errorf("variable [%s] not found", variableName) case err != nil: return nil, err @@ -101,13 +101,13 @@ func (c *ConfigService) DeleteVariable(variableName string) error { err := c.configRepo.DeleteVariable(variableName) switch { - case errors.Is(err, entity.ErrVariableNotFound): + case errors.Is(err, model.ErrVariableNotFound): return errors.Errorf("variable [%s] not found", variableName) default: return err } } -func (c *ConfigService) UpsertVariables(vars []entity.UpsertVariableRequest) error { +func (c *ConfigService) UpsertVariables(vars []model.UpsertVariableRequest) error { return c.configRepo.UpsertVariables(vars) }