MSP-5014 Rename entity to model

This commit is contained in:
Синельник Тимур Романович committed 2025-03-21 10:08:25 +03:00
1 parent 69319f0d2b
commit 418c4e757f
6 files changed
+43 -43

No files matched your search

+2 -2
View File
@@ -1,11 +1,11 @@
package utils package utils
import ( import (
"ispctl/entity" "ispctl/model"
"ispctl/service" "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) answer, err := service.Config.CreateUpdateConfig(stringToChange, configuration)
if err != nil { if err != nil {
return err return err
+7 -7
View File
@@ -6,7 +6,7 @@ import (
"ispctl/bash" "ispctl/bash"
"ispctl/command/flag" "ispctl/command/flag"
"ispctl/command/utils" "ispctl/command/utils"
"ispctl/entity" "ispctl/model"
"ispctl/service" "ispctl/service"
"os" "os"
"strings" "strings"
@@ -97,11 +97,11 @@ func (g varsCommands) getByName(ctx *cli.Context) error {
func (g varsCommands) set(ctx *cli.Context) error { func (g varsCommands) set(ctx *cli.Context) error {
variableName := ctx.Args().Get(0) variableName := ctx.Args().Get(0)
variableValue := ctx.Args().Get(1) variableValue := ctx.Args().Get(1)
variableType := entity.TextVariableType variableType := model.TextVariableType
if ctx.Bool(flag.SetVariableSecretType.Name) { 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, Name: variableName,
Value: variableValue, Value: variableValue,
Type: variableType, Type: variableType,
@@ -120,7 +120,7 @@ func (g varsCommands) upload(ctx *cli.Context) error {
return service.Config.UpsertVariables(variables) 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) file, err := os.Open(filepath)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to open file %s: %w", filepath, err) 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 { for i, col := range header {
columnIndexes[strings.ToLower(col)] = i 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:] { for _, row := range records[1:] {
variables = append(variables, entity.UpsertVariableRequest{ variables = append(variables, model.UpsertVariableRequest{
Name: row[columnIndexes["name"]], Name: row[columnIndexes["name"]],
Type: row[columnIndexes["type"]], Type: row[columnIndexes["type"]],
Value: row[columnIndexes["value"]], Value: row[columnIndexes["value"]],
+1 -1
View File
@@ -1,4 +1,4 @@
package entity package model
import ( import (
"time" "time"
+1 -1
View File
@@ -1,4 +1,4 @@
package entity package model
import "github.com/pkg/errors" import "github.com/pkg/errors"
+21 -21
View File
@@ -4,7 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
epb "google.golang.org/genproto/googleapis/rpc/errdetails" epb "google.golang.org/genproto/googleapis/rpc/errdetails"
"ispctl/entity" "ispctl/model"
"strings" "strings"
"time" "time"
@@ -39,8 +39,8 @@ func NewConfig(cli *client.Client) Config {
} }
} }
func (c Config) GetAvailableConfigs() ([]entity.ModuleInfo, error) { func (c Config) GetAvailableConfigs() ([]model.ModuleInfo, error) {
response := make([]entity.ModuleInfo, 0) response := make([]model.ModuleInfo, 0)
err := c.cli.Invoke(getAvailableConfigs). err := c.cli.Invoke(getAvailableConfigs).
JsonResponseBody(&response). JsonResponseBody(&response).
Timeout(time.Second). Timeout(time.Second).
@@ -51,9 +51,9 @@ func (c Config) GetAvailableConfigs() ([]entity.ModuleInfo, error) {
return response, nil return response, nil
} }
func (c Config) GetConfigByModuleName(name string) (*entity.Config, error) { func (c Config) GetConfigByModuleName(name string) (*model.Config, error) {
request := &entity.GetModuleByUuidAndNameRequest{ModuleName: name} request := &model.GetModuleByUuidAndNameRequest{ModuleName: name}
response := new(entity.Config) response := new(model.Config)
err := c.cli.Invoke(getConfigByModuleName). err := c.cli.Invoke(getConfigByModuleName).
JsonRequestBody(request). JsonRequestBody(request).
JsonResponseBody(&response). JsonResponseBody(&response).
@@ -61,7 +61,7 @@ func (c Config) GetConfigByModuleName(name string) (*entity.Config, error) {
Do(c.baseCtx) Do(c.baseCtx)
switch { switch {
case status.Code(err) == codes.NotFound: case status.Code(err) == codes.NotFound:
return nil, entity.ErrModuleNotFound return nil, model.ErrModuleNotFound
case err != nil: case err != nil:
return nil, errors.WithMessagef(err, "call %s", getConfigByModuleName) return nil, errors.WithMessagef(err, "call %s", getConfigByModuleName)
default: default:
@@ -69,8 +69,8 @@ func (c Config) GetConfigByModuleName(name string) (*entity.Config, error) {
} }
} }
func (c Config) CreateUpdateConfig(request entity.Config) (*entity.Config, error) { func (c Config) CreateUpdateConfig(request model.Config) (*model.Config, error) {
response := new(entity.Config) response := new(model.Config)
err := c.cli.Invoke(createUpdateConfig). err := c.cli.Invoke(createUpdateConfig).
JsonRequestBody(request). JsonRequestBody(request).
JsonResponseBody(&response). JsonResponseBody(&response).
@@ -82,9 +82,9 @@ func (c Config) CreateUpdateConfig(request entity.Config) (*entity.Config, error
return response, nil return response, nil
} }
func (c Config) GetSchemaByModuleId(moduleId string) (*entity.ConfigSchema, error) { func (c Config) GetSchemaByModuleId(moduleId string) (*model.ConfigSchema, error) {
request := entity.GetSchemaByModuleIdRequest{ModuleId: moduleId} request := model.GetSchemaByModuleIdRequest{ModuleId: moduleId}
response := new(entity.ConfigSchema) response := new(model.ConfigSchema)
err := c.cli.Invoke(getSchemaByModuleId). err := c.cli.Invoke(getSchemaByModuleId).
JsonRequestBody(request). JsonRequestBody(request).
JsonResponseBody(&response). JsonResponseBody(&response).
@@ -96,8 +96,8 @@ func (c Config) GetSchemaByModuleId(moduleId string) (*entity.ConfigSchema, erro
return response, nil return response, nil
} }
func (c Config) GetAllVariables() ([]entity.Variable, error) { func (c Config) GetAllVariables() ([]model.Variable, error) {
response := make([]entity.Variable, 0) response := make([]model.Variable, 0)
err := c.cli.Invoke(getAllVariables). err := c.cli.Invoke(getAllVariables).
JsonResponseBody(&response). JsonResponseBody(&response).
Timeout(time.Second). Timeout(time.Second).
@@ -108,9 +108,9 @@ func (c Config) GetAllVariables() ([]entity.Variable, error) {
return response, nil return response, nil
} }
func (c Config) GetVariableByName(variableName string) (*entity.Variable, error) { func (c Config) GetVariableByName(variableName string) (*model.Variable, error) {
request := entity.VariableByNameRequest{Name: variableName} request := model.VariableByNameRequest{Name: variableName}
response := new(entity.Variable) response := new(model.Variable)
err := c.cli.Invoke(getVariableByName). err := c.cli.Invoke(getVariableByName).
JsonRequestBody(request). JsonRequestBody(request).
JsonResponseBody(&response). JsonResponseBody(&response).
@@ -122,7 +122,7 @@ func (c Config) GetVariableByName(variableName string) (*entity.Variable, error)
return response, nil return response, nil
} }
func (c Config) UpsertVariables(request []entity.UpsertVariableRequest) error { func (c Config) UpsertVariables(request []model.UpsertVariableRequest) error {
err := c.cli.Invoke(upsertVariable). err := c.cli.Invoke(upsertVariable).
JsonRequestBody(request). JsonRequestBody(request).
Timeout(time.Second). Timeout(time.Second).
@@ -134,7 +134,7 @@ func (c Config) UpsertVariables(request []entity.UpsertVariableRequest) error {
} }
func (c Config) DeleteVariable(variableName string) error { func (c Config) DeleteVariable(variableName string) error {
request := entity.VariableByNameRequest{Name: variableName} request := model.VariableByNameRequest{Name: variableName}
err := c.cli.Invoke(deleteVariable). err := c.cli.Invoke(deleteVariable).
JsonRequestBody(request). JsonRequestBody(request).
Timeout(time.Second). Timeout(time.Second).
@@ -151,8 +151,8 @@ func (c Config) handleVariableError(err error, endpoint string) error {
return errors.WithMessagef(err, "call %s", endpoint) return errors.WithMessagef(err, "call %s", endpoint)
} }
switch { switch {
case apiError.ErrorCode == entity.ErrCodeVariableNotFound: case apiError.ErrorCode == model.ErrCodeVariableNotFound:
return entity.ErrVariableNotFound return model.ErrVariableNotFound
default: default:
return errors.WithMessagef(err, "call %s", endpoint) return errors.WithMessagef(err, "call %s", endpoint)
} }
+11 -11
View File
@@ -3,7 +3,7 @@ package service
import ( import (
"encoding/json" "encoding/json"
"ispctl/entity" "ispctl/model"
"ispctl/repository" "ispctl/repository"
"github.com/pkg/errors" "github.com/pkg/errors"
@@ -26,18 +26,18 @@ func (c *ConfigService) ReceiveConfiguration(host string) error {
return nil return nil
} }
func (c *ConfigService) GetAvailableConfigs() ([]entity.ModuleInfo, error) { func (c *ConfigService) GetAvailableConfigs() ([]model.ModuleInfo, error) {
return c.configRepo.GetAvailableConfigs() return c.configRepo.GetAvailableConfigs()
} }
func (c *ConfigService) GetConfigurationByModuleName(moduleName string) (*entity.Config, error) { func (c *ConfigService) GetConfigurationByModuleName(moduleName string) (*model.Config, error) {
if moduleName == "" { if moduleName == "" {
return nil, errors.New("need module name") return nil, errors.New("need module name")
} }
moduleConfiguration, err := c.configRepo.GetConfigByModuleName(moduleName) moduleConfiguration, err := c.configRepo.GetConfigByModuleName(moduleName)
switch { switch {
case errors.Is(err, entity.ErrModuleNotFound): case errors.Is(err, model.ErrModuleNotFound):
return nil, errors.Errorf("module [%s] not found", moduleName) return nil, errors.Errorf("module [%s] not found", moduleName)
default: default:
return moduleConfiguration, err return moduleConfiguration, err
@@ -52,7 +52,7 @@ func (c *ConfigService) GetSchemaByModuleId(moduleId string) (schema.Schema, err
return configSchema.Schema, nil 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) newData := make(map[string]any)
if stringToChange != "" { if stringToChange != "" {
err := json.Unmarshal([]byte(stringToChange), &newData) err := json.Unmarshal([]byte(stringToChange), &newData)
@@ -65,7 +65,7 @@ func (c *ConfigService) CreateUpdateConfig(stringToChange string, configuration
return c.CreateUpdateConfigV2(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 configuration.Unsafe = c.UnsafeEnable
resp, err := c.configRepo.CreateUpdateConfig(*configuration) resp, err := c.configRepo.CreateUpdateConfig(*configuration)
if err != nil { if err != nil {
@@ -74,18 +74,18 @@ func (c *ConfigService) CreateUpdateConfigV2(configuration *entity.Config) (map[
return resp.Data, nil return resp.Data, nil
} }
func (c *ConfigService) GetAllVariables() ([]entity.Variable, error) { func (c *ConfigService) GetAllVariables() ([]model.Variable, error) {
return c.configRepo.GetAllVariables() return c.configRepo.GetAllVariables()
} }
func (c *ConfigService) GetVariableByName(variableName string) (*entity.Variable, error) { func (c *ConfigService) GetVariableByName(variableName string) (*model.Variable, error) {
if variableName == "" { if variableName == "" {
return nil, errors.New("need variable name") return nil, errors.New("need variable name")
} }
variable, err := c.configRepo.GetVariableByName(variableName) variable, err := c.configRepo.GetVariableByName(variableName)
switch { switch {
case errors.Is(err, entity.ErrVariableNotFound): case errors.Is(err, model.ErrVariableNotFound):
return nil, errors.Errorf("variable [%s] not found", variableName) return nil, errors.Errorf("variable [%s] not found", variableName)
case err != nil: case err != nil:
return nil, err return nil, err
@@ -101,13 +101,13 @@ func (c *ConfigService) DeleteVariable(variableName string) error {
err := c.configRepo.DeleteVariable(variableName) err := c.configRepo.DeleteVariable(variableName)
switch { switch {
case errors.Is(err, entity.ErrVariableNotFound): case errors.Is(err, model.ErrVariableNotFound):
return errors.Errorf("variable [%s] not found", variableName) return errors.Errorf("variable [%s] not found", variableName)
default: default:
return err return err
} }
} }
func (c *ConfigService) UpsertVariables(vars []entity.UpsertVariableRequest) error { func (c *ConfigService) UpsertVariables(vars []model.UpsertVariableRequest) error {
return c.configRepo.UpsertVariables(vars) return c.configRepo.UpsertVariables(vars)
} }