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
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
+7 -7
View File
@@ -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"]],
+1 -1
View File
@@ -1,4 +1,4 @@
package entity
package model
import (
"time"
+1 -1
View File
@@ -1,4 +1,4 @@
package entity
package model
import "github.com/pkg/errors"
+21 -21
View File
@@ -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)
}
+11 -11
View File
@@ -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)
}