MSP-5013 Update doc
This commit is contained in:
1 parent
be0dea3702
commit
d6a8f77610
11 files changed
+256
-62
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user