MSP-5013 Update doc
This commit is contained in:
1 parent
be0dea3702
commit
d6a8f77610
11 files changed
+256
-62
No files matched your search
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"isp-config-service/conf"
|
||||
"isp-config-service/service/module/backend"
|
||||
"isp-config-service/service/variable"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
@@ -141,12 +142,16 @@ func (l Locator) Config() *Config {
|
||||
configSchemaApiService := apisvs.NewConfigSchema(configSchemaRepo)
|
||||
configSchemaController := api.NewConfigSchema(configSchemaApiService)
|
||||
|
||||
variableService := variable.NewService()
|
||||
variableController := api.NewVariable(variableService)
|
||||
|
||||
controllers := routes.Controllers{
|
||||
Module: moduleController,
|
||||
ModuleApi: moduleApiController,
|
||||
ConfigApi: configApiController,
|
||||
ConfigHistoryApi: configHistoryController,
|
||||
ConfigSchemaApi: configSchemaController,
|
||||
VariableApi: variableController,
|
||||
}
|
||||
mapper := endpoint.DefaultWrapper(l.logger)
|
||||
grpcMux := routes.GrpcHandler(mapper, controllers)
|
||||
|
||||
@@ -2,11 +2,30 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
_ "github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
All(ctx context.Context) ([]domain.Variable, error)
|
||||
GetByName(ctx context.Context, name string) (*domain.Variable, error)
|
||||
Create(ctx context.Context, req domain.CreateVariableRequest) (*domain.Variable, error)
|
||||
Update(ctx context.Context, req domain.UpdateVariableRequest) (*domain.Variable, error)
|
||||
Upsert(ctx context.Context, req []domain.UpsertVariableRequest) error
|
||||
Delete(ctx context.Context, name string) (*domain.Variable, error)
|
||||
}
|
||||
|
||||
type Variable struct {
|
||||
service Service
|
||||
}
|
||||
|
||||
func NewVariable(service Service) Variable {
|
||||
return Variable{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// All
|
||||
@@ -18,7 +37,7 @@ type Variable struct {
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/all [POST]
|
||||
func (c Variable) All(ctx context.Context) ([]domain.Variable, error) {
|
||||
|
||||
return c.service.All(ctx)
|
||||
}
|
||||
|
||||
// GetByName
|
||||
@@ -32,7 +51,14 @@ func (c Variable) All(ctx context.Context) ([]domain.Variable, error) {
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/get_by_name [POST]
|
||||
func (c Variable) GetByName(ctx context.Context, req domain.VariableByNameRequest) (*domain.Variable, error) {
|
||||
|
||||
v, err := c.service.GetByName(ctx, req.Name)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrVariableNotFound):
|
||||
return nil, apierrors.NewBusinessError(domain.ErrorCodeVariableNotFound, "variable by name not found", err)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Create
|
||||
@@ -47,7 +73,14 @@ func (c Variable) GetByName(ctx context.Context, req domain.VariableByNameReques
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/create [POST]
|
||||
func (c Variable) Create(ctx context.Context, req domain.CreateVariableRequest) (*domain.Variable, error) {
|
||||
|
||||
v, err := c.service.Create(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrVariableAlreadyExists):
|
||||
return nil, apierrors.NewBusinessError(domain.ErrorCodeVariableAlreadyExists, "variable with the same name already exists", err)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Update
|
||||
@@ -58,10 +91,18 @@ func (c Variable) Create(ctx context.Context, req domain.CreateVariableRequest)
|
||||
// @Produce json
|
||||
// @Param body body domain.UpdateVariableRequest true "тело запроса"
|
||||
// @Success 200 {object} domain.Variable
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2006` - переменная по имени не найдена<br/>"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/update [POST]
|
||||
func (c Variable) Update(ctx context.Context, req domain.UpdateVariableRequest) (*domain.Variable, error) {
|
||||
|
||||
v, err := c.service.Update(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrVariableNotFound):
|
||||
return nil, apierrors.NewBusinessError(domain.ErrorCodeVariableNotFound, "variable by name not found", err)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Upsert
|
||||
@@ -76,7 +117,11 @@ func (c Variable) Update(ctx context.Context, req domain.UpdateVariableRequest)
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/upsert [POST]
|
||||
func (c Variable) Upsert(ctx context.Context, req []domain.UpsertVariableRequest) error {
|
||||
|
||||
err := c.service.Upsert(ctx, req)
|
||||
if err != nil {
|
||||
return apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete
|
||||
@@ -91,5 +136,14 @@ func (c Variable) Upsert(ctx context.Context, req []domain.UpsertVariableRequest
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /variable/delete [POST]
|
||||
func (c Variable) Delete(ctx context.Context, req domain.VariableByNameRequest) (*domain.Variable, error) {
|
||||
|
||||
v, err := c.service.Delete(ctx, req.Name)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrConfigNotFound):
|
||||
return nil, apierrors.NewBusinessError(domain.ErrorCodeVariableNotFound, "variable by name not found", err)
|
||||
case errors.Is(err, entity.ErrVariableUsedInConfigs):
|
||||
return nil, apierrors.NewBusinessError(domain.ErrorCodeVariableUsedInConfigs, "variable used in configs", err)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
+6
-2
@@ -145,6 +145,8 @@ definitions:
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
moduleId:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
type: object
|
||||
@@ -204,8 +206,6 @@ definitions:
|
||||
type: string
|
||||
description:
|
||||
type: string
|
||||
id:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
type:
|
||||
@@ -718,6 +718,10 @@ paths:
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/domain.Variable'
|
||||
"400":
|
||||
description: '`errorCode: 2006` - переменная по имени не найдена<br/>'
|
||||
schema:
|
||||
$ref: '#/definitions/github_com_txix-open_isp-kit_grpc_apierrors.Error'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
|
||||
+3
-3
@@ -3,7 +3,6 @@ package domain
|
||||
import "time"
|
||||
|
||||
type Variable struct {
|
||||
Id string
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
@@ -14,8 +13,9 @@ type Variable struct {
|
||||
}
|
||||
|
||||
type LinkedConfig struct {
|
||||
Id string
|
||||
Name string
|
||||
Id string
|
||||
ModuleId string
|
||||
Name string
|
||||
}
|
||||
|
||||
type CreateVariableRequest struct {
|
||||
|
||||
@@ -10,4 +10,7 @@ var (
|
||||
ErrSchemaNotFound = errors.New("config schema not found")
|
||||
ErrConfigNotFoundOrActive = errors.New("config not found or markers as active")
|
||||
ErrConfigConflictUpdate = errors.New("config conflict update")
|
||||
ErrVariableNotFound = errors.New("variable not found")
|
||||
ErrVariableAlreadyExists = errors.New("variable already exists")
|
||||
ErrVariableUsedInConfigs = errors.New("variable used in configs")
|
||||
)
|
||||
@@ -0,0 +1,19 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"isp-config-service/entity/xtypes"
|
||||
)
|
||||
|
||||
type Variable struct {
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
Value string
|
||||
CreatedAt xtypes.Time
|
||||
UpdatedAt xtypes.Time
|
||||
}
|
||||
|
||||
type ConfigHasVariable struct {
|
||||
ConfigId string
|
||||
VariableName string
|
||||
}
|
||||
@@ -268,8 +268,6 @@ github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIg
|
||||
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
||||
github.com/txix-open/grmq v1.7.0 h1:nwenrlxEjXpK0EBCa/WbIxK+y0mF2pZxNKbheFjQVsI=
|
||||
github.com/txix-open/grmq v1.7.0/go.mod h1:DAfbV4jLyxQBLG8OYJVy8kCbhucdlu/C/wl+nUDc9p8=
|
||||
github.com/txix-open/isp-kit v1.42.1 h1:1YB0AqO3Mu0mUrghmtpsBdFJV20rsoxq68nqBWLyYQU=
|
||||
github.com/txix-open/isp-kit v1.42.1/go.mod h1:BHRF3AYRcQtEtNvoQZXxTVj/CYOVMKhOcCD3n8CdsxE=
|
||||
github.com/txix-open/isp-kit v1.43.0 h1:fVVa8WNGSShtK935ypOAN1eQCY7Y4bqr17A3JCbp6mA=
|
||||
github.com/txix-open/isp-kit v1.43.0/go.mod h1:BHRF3AYRcQtEtNvoQZXxTVj/CYOVMKhOcCD3n8CdsxE=
|
||||
github.com/txix-open/jsonschema v1.2.0 h1:B8TrdSsPhDvYv67oi/LVqf7/+PuqFlMsNwUzGeHfl1s=
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
-- +goose Up
|
||||
-- +goose NO TRANSACTION
|
||||
create table isp_config_service__variable
|
||||
(
|
||||
name text primary key,
|
||||
description text not null,
|
||||
type text not null,
|
||||
value text not null,
|
||||
created_at integer not null default (unixepoch()),
|
||||
update_at integer not null default (unixepoch())
|
||||
);
|
||||
|
||||
create table isp_config_service__config_has_variable
|
||||
(
|
||||
config_id text not null,
|
||||
variable_name text not null,
|
||||
primary key (config_id, variable_name),
|
||||
foreign key (config_id) references isp_config_service__config (id) on delete cascade on update cascade,
|
||||
foreign key (variable_name) references isp_config_service__variable (name)
|
||||
);
|
||||
|
||||
create index IX_isp_config_service__config_has_variable__variable_name on isp_config_service__config_has_variable (variable_name);
|
||||
|
||||
-- +goose Down
|
||||
drop table isp_config_service__config_has_variable;
|
||||
drop table isp_config_service__variable;
|
||||
@@ -0,0 +1,13 @@
|
||||
package repository
|
||||
|
||||
import "isp-config-service/service/rqlite/db"
|
||||
|
||||
type Variable struct {
|
||||
db db.DB
|
||||
}
|
||||
|
||||
func NewVariable(db db.DB) Variable {
|
||||
return Variable{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
+81
-49
@@ -20,6 +20,7 @@ type Controllers struct {
|
||||
ConfigApi api.Config
|
||||
ConfigHistoryApi api.ConfigHistory
|
||||
ConfigSchemaApi api.ConfigSchema
|
||||
VariableApi api.Variable
|
||||
}
|
||||
|
||||
func EndpointDescriptors() []cluster.EndpointDescriptor {
|
||||
@@ -63,53 +64,84 @@ func HttpHandler(etpSrv *etp.Server, conf conf.Local, rqliteProxy http.Handler)
|
||||
}
|
||||
|
||||
func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
||||
return []cluster.EndpointDescriptor{{
|
||||
Path: "config/module/get_modules_info",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.Status,
|
||||
}, {
|
||||
Path: "config/module/delete_module",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.DeleteModule,
|
||||
}, {
|
||||
Path: "config/routing/get_routes",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.Connections,
|
||||
}, {
|
||||
Path: "config/config/get_active_config_by_module_name",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetActiveConfigByModuleName,
|
||||
}, {
|
||||
Path: "config/config/get_configs_by_module_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetConfigsByModuleId,
|
||||
}, {
|
||||
Path: "config/config/create_update_config",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.CreateUpdateConfig,
|
||||
}, {
|
||||
Path: "config/config/get_config_by_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetConfigById,
|
||||
}, {
|
||||
Path: "config/config/mark_config_as_active",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.MarkConfigAsActive,
|
||||
}, {
|
||||
Path: "config/config/delete_config",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.DeleteConfigs,
|
||||
}, {
|
||||
Path: "config/config/get_all_version",
|
||||
Inner: true,
|
||||
Handler: c.ConfigHistoryApi.GetAllVersion,
|
||||
}, {
|
||||
Path: "config/config/delete_version",
|
||||
Inner: true,
|
||||
Handler: c.ConfigHistoryApi.DeleteConfigVersion,
|
||||
}, {
|
||||
Path: "config/schema/get_by_module_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigSchemaApi.SchemaByModuleId,
|
||||
}}
|
||||
return []cluster.EndpointDescriptor{
|
||||
//modules
|
||||
{
|
||||
Path: "config/module/get_modules_info",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.Status,
|
||||
}, {
|
||||
Path: "config/module/delete_module",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.DeleteModule,
|
||||
}, {
|
||||
Path: "config/routing/get_routes",
|
||||
Inner: true,
|
||||
Handler: c.ModuleApi.Connections,
|
||||
},
|
||||
//configs
|
||||
{
|
||||
Path: "config/config/get_active_config_by_module_name",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetActiveConfigByModuleName,
|
||||
}, {
|
||||
Path: "config/config/get_configs_by_module_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetConfigsByModuleId,
|
||||
}, {
|
||||
Path: "config/config/create_update_config",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.CreateUpdateConfig,
|
||||
}, {
|
||||
Path: "config/config/get_config_by_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.GetConfigById,
|
||||
}, {
|
||||
Path: "config/config/mark_config_as_active",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.MarkConfigAsActive,
|
||||
}, {
|
||||
Path: "config/config/delete_config",
|
||||
Inner: true,
|
||||
Handler: c.ConfigApi.DeleteConfigs,
|
||||
}, {
|
||||
Path: "config/config/get_all_version",
|
||||
Inner: true,
|
||||
Handler: c.ConfigHistoryApi.GetAllVersion,
|
||||
}, {
|
||||
Path: "config/config/delete_version",
|
||||
Inner: true,
|
||||
Handler: c.ConfigHistoryApi.DeleteConfigVersion,
|
||||
}, {
|
||||
Path: "config/schema/get_by_module_id",
|
||||
Inner: true,
|
||||
Handler: c.ConfigSchemaApi.SchemaByModuleId,
|
||||
},
|
||||
//variables
|
||||
{
|
||||
Path: "variable/all",
|
||||
Inner: true,
|
||||
Handler: c.VariableApi.All,
|
||||
}, {
|
||||
Path: "variable/get_by_name",
|
||||
Inner: true,
|
||||
Handler: c.VariableApi.GetByName,
|
||||
}, {
|
||||
Path: "variable/create",
|
||||
Inner: true,
|
||||
Handler: c.VariableApi.Create,
|
||||
}, {
|
||||
Path: "variable/update",
|
||||
Inner: true,
|
||||
Handler: c.VariableApi.Update,
|
||||
}, {
|
||||
Path: "variable/upsert",
|
||||
Inner: true,
|
||||
Handler: c.VariableApi.Upsert,
|
||||
}, {
|
||||
Path: "variable/delete",
|
||||
Inner: true,
|
||||
Handler: c.VariableApi.Delete,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package variable
|
||||
|
||||
import (
|
||||
"context"
|
||||
"isp-config-service/domain"
|
||||
)
|
||||
|
||||
type Repo interface {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
}
|
||||
|
||||
func NewService() Service {
|
||||
|
||||
}
|
||||
|
||||
func (s Service) All(ctx context.Context) ([]domain.Variable, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s Service) GetByName(ctx context.Context, name string) (*domain.Variable, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s Service) Create(ctx context.Context, req domain.CreateVariableRequest) (*domain.Variable, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s Service) Update(ctx context.Context, req domain.UpdateVariableRequest) (*domain.Variable, error) {
|
||||
|
||||
}
|
||||
|
||||
func (s Service) Upsert(ctx context.Context, req []domain.UpsertVariableRequest) error {
|
||||
|
||||
}
|
||||
|
||||
func (s Service) Delete(ctx context.Context, name string) (*domain.Variable, error) {
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user