MSP-5186 Use apierrrors.Error

This commit is contained in:
Синельник Тимур Романович committed 2025-04-03 14:01:25 +03:00
1 parent 3b43e7875d
commit 199d576956
12 files changed
+333 -213

No files matched your search

+28 -11
View File
@@ -2,11 +2,13 @@ package controller
import ( import (
"context" "context"
"fmt"
"isp-system-service/domain"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/grpc/apierrors"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"isp-system-service/domain"
) )
type AccessListService interface { type AccessListService interface {
@@ -34,14 +36,19 @@ func NewAccessList(service AccessListService) AccessList {
// @Produce json // @Produce json
// @Param body body domain.Identity false "идентификатор приложения" // @Param body body domain.Identity false "идентификатор приложения"
// @Success 200 {array} domain.MethodInfo "список доступности методов" // @Success 200 {array} domain.MethodInfo "список доступности методов"
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /access_list/get_by_id [POST] // @Router /access_list/get_by_id [POST]
func (c AccessList) GetById(ctx context.Context, req domain.Identity) ([]domain.MethodInfo, error) { func (c AccessList) GetById(ctx context.Context, req domain.Identity) ([]domain.MethodInfo, error) {
result, err := c.service.GetById(ctx, req.Id) result, err := c.service.GetById(ctx, req.Id)
switch { switch {
case errors.Is(err, domain.ErrApplicationNotFound): case errors.Is(err, domain.ErrApplicationNotFound):
return nil, status.Errorf(codes.NotFound, "application not found") return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeApplicationNotFound,
fmt.Sprintf("application with id %d not found", req.Id),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -58,14 +65,19 @@ func (c AccessList) GetById(ctx context.Context, req domain.Identity) ([]domain.
// @Produce json // @Produce json
// @Param body body domain.AccessListSetOneRequest false "объект для настройки доступа" // @Param body body domain.AccessListSetOneRequest false "объект для настройки доступа"
// @Success 200 {object} domain.AccessListSetOneResponse "количество измененных строк" // @Success 200 {object} domain.AccessListSetOneResponse "количество измененных строк"
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /access_list/set_one [POST] // @Router /access_list/set_one [POST]
func (c AccessList) SetOne(ctx context.Context, req domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error) { func (c AccessList) SetOne(ctx context.Context, req domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error) {
result, err := c.service.SetOne(ctx, req) result, err := c.service.SetOne(ctx, req)
switch { switch {
case errors.Is(err, domain.ErrApplicationNotFound): case errors.Is(err, domain.ErrApplicationNotFound):
return nil, status.Errorf(codes.NotFound, "application not found") return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeApplicationNotFound,
fmt.Sprintf("application with id %d not found", req.AppId),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -82,14 +94,19 @@ func (c AccessList) SetOne(ctx context.Context, req domain.AccessListSetOneReque
// @Produce json // @Produce json
// @Param body body domain.AccessListSetListRequest false "объект настройки доступа" // @Param body body domain.AccessListSetListRequest false "объект настройки доступа"
// @Success 200 {array} domain.MethodInfo "список доступности методов" // @Success 200 {array} domain.MethodInfo "список доступности методов"
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /access_list/set_list [POST] // @Router /access_list/set_list [POST]
func (c AccessList) SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error) { func (c AccessList) SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error) {
result, err := c.service.SetList(ctx, req) result, err := c.service.SetList(ctx, req)
switch { switch {
case errors.Is(err, domain.ErrApplicationNotFound): case errors.Is(err, domain.ErrApplicationNotFound):
return nil, status.Errorf(codes.NotFound, "application not found") return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeApplicationNotFound,
fmt.Sprintf("application with id %d not found", req.AppId),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
+31 -15
View File
@@ -2,11 +2,12 @@ package controller
import ( import (
"context" "context"
"fmt"
"isp-system-service/domain" "isp-system-service/domain"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/grpc/apierrors"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
type AppGroupService interface { type AppGroupService interface {
@@ -35,15 +36,20 @@ func NewAppGroup(service AppGroupService) AppGroup {
// @Produce json // @Produce json
// @Param body body domain.CreateAppGroupRequest true "Объект группы приложений" // @Param body body domain.CreateAppGroupRequest true "Объект группы приложений"
// @Success 200 {object} domain.AppGroup // @Success 200 {object} domain.AppGroup
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 409 {object} domain.GrpcError // @Failure 409 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application_group/create [POST] // @Router /application_group/create [POST]
func (c AppGroup) Create(ctx context.Context, req domain.CreateAppGroupRequest) (*domain.AppGroup, error) { func (c AppGroup) Create(ctx context.Context, req domain.CreateAppGroupRequest) (*domain.AppGroup, error) {
result, err := c.service.Create(ctx, req) result, err := c.service.Create(ctx, req)
switch { switch {
case errors.Is(err, domain.ErrAppGroupDuplicateName): case errors.Is(err, domain.ErrAppGroupDuplicateName):
return nil, status.Errorf(codes.AlreadyExists, "application group with name %s already exists", req.Name) return nil, apierrors.New(
codes.AlreadyExists,
domain.ErrCodeAppGroupDuplicateName,
fmt.Sprintf("application group with name %s already exists", req.Name),
err,
)
default: default:
return result, err return result, err
} }
@@ -58,18 +64,28 @@ func (c AppGroup) Create(ctx context.Context, req domain.CreateAppGroupRequest)
// @Produce json // @Produce json
// @Param body body domain.UpdateAppGroupRequest true "Объект группы приложений" // @Param body body domain.UpdateAppGroupRequest true "Объект группы приложений"
// @Success 200 {object} domain.AppGroup // @Success 200 {object} domain.AppGroup
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 409 {object} domain.GrpcError // @Failure 409 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application_group/update [POST] // @Router /application_group/update [POST]
func (c AppGroup) Update(ctx context.Context, req domain.UpdateAppGroupRequest) (*domain.AppGroup, error) { func (c AppGroup) Update(ctx context.Context, req domain.UpdateAppGroupRequest) (*domain.AppGroup, error) {
result, err := c.service.Update(ctx, req) result, err := c.service.Update(ctx, req)
switch { switch {
case errors.Is(err, domain.ErrAppGroupDuplicateName): case errors.Is(err, domain.ErrAppGroupDuplicateName):
return nil, status.Errorf(codes.AlreadyExists, "application group with name %s already exists", req.Name) return nil, apierrors.New(
codes.AlreadyExists,
domain.ErrCodeAppGroupDuplicateName,
fmt.Sprintf("application group with name %s already exists", req.Name),
err,
)
case errors.Is(err, domain.ErrAppGroupNotFound): case errors.Is(err, domain.ErrAppGroupNotFound):
return nil, status.Errorf(codes.NotFound, "application group with id %d not found", req.Id) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeAppGroupNotFound,
fmt.Sprintf("application group with id %d not found", req.Id),
err,
)
default: default:
return result, err return result, err
} }
@@ -84,8 +100,8 @@ func (c AppGroup) Update(ctx context.Context, req domain.UpdateAppGroupRequest)
// @Produce json // @Produce json
// @Param body body domain.IdListRequest true "список идентификаторов групп приложений" // @Param body body domain.IdListRequest true "список идентификаторов групп приложений"
// @Success 200 {object} domain.DeleteResponse // @Success 200 {object} domain.DeleteResponse
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application_group/delete_list [POST] // @Router /application_group/delete_list [POST]
func (c AppGroup) DeleteList(ctx context.Context, req domain.IdListRequest) (*domain.DeleteResponse, error) { func (c AppGroup) DeleteList(ctx context.Context, req domain.IdListRequest) (*domain.DeleteResponse, error) {
return c.service.DeleteList(ctx, req) return c.service.DeleteList(ctx, req)
@@ -100,8 +116,8 @@ func (c AppGroup) DeleteList(ctx context.Context, req domain.IdListRequest) (*do
// @Produce json // @Produce json
// @Param body body domain.IdListRequest true "список идентификаторов групп приложений" // @Param body body domain.IdListRequest true "список идентификаторов групп приложений"
// @Success 200 {array} domain.AppGroup // @Success 200 {array} domain.AppGroup
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application_group/get_by_id_list [POST] // @Router /application_group/get_by_id_list [POST]
func (c AppGroup) GetByIdList(ctx context.Context, req domain.IdListRequest) ([]domain.AppGroup, error) { func (c AppGroup) GetByIdList(ctx context.Context, req domain.IdListRequest) ([]domain.AppGroup, error) {
return c.service.GetByIdList(ctx, req.IdList) return c.service.GetByIdList(ctx, req.IdList)
+61 -26
View File
@@ -2,12 +2,13 @@ package controller
import ( import (
"context" "context"
"fmt"
"isp-system-service/domain" "isp-system-service/domain"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/grpc/apierrors"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
type ApplicationService interface { type ApplicationService interface {
@@ -42,15 +43,20 @@ func NewApplication(service ApplicationService) Application {
// @Produce json // @Produce json
// @Param body body domain.Identity true "Идентификатор приложения" // @Param body body domain.Identity true "Идентификатор приложения"
// @Success 200 {object} domain.ApplicationWithTokens // @Success 200 {object} domain.ApplicationWithTokens
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/get_application_by_id [POST] // @Router /application/get_application_by_id [POST]
func (c Application) GetById(ctx context.Context, req domain.Identity) (*domain.ApplicationWithTokens, error) { func (c Application) GetById(ctx context.Context, req domain.Identity) (*domain.ApplicationWithTokens, error) {
result, err := c.service.GetById(ctx, req.Id) result, err := c.service.GetById(ctx, req.Id)
switch { switch {
case errors.Is(err, domain.ErrApplicationNotFound): case errors.Is(err, domain.ErrApplicationNotFound):
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.Id) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeApplicationNotFound,
fmt.Sprintf("application with id %d not found", req.Id),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -67,7 +73,7 @@ func (c Application) GetById(ctx context.Context, req domain.Identity) (*domain.
// @Produce json // @Produce json
// @Param body body []integer false "Массив идентификаторов приложений" // @Param body body []integer false "Массив идентификаторов приложений"
// @Success 200 {array} domain.ApplicationWithTokens // @Success 200 {array} domain.ApplicationWithTokens
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/get_applications [POST] // @Router /application/get_applications [POST]
func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.ApplicationWithTokens, error) { func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.ApplicationWithTokens, error) {
return c.service.GetByIdList(ctx, req) return c.service.GetByIdList(ctx, req)
@@ -82,7 +88,7 @@ func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.Appl
// @Produce json // @Produce json
// @Param body body domain.Identity true "Идентификатор сервиса" // @Param body body domain.Identity true "Идентификатор сервиса"
// @Success 200 {array} domain.ApplicationWithTokens // @Success 200 {array} domain.ApplicationWithTokens
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/get_applications_by_service_id [POST] // @Router /application/get_applications_by_service_id [POST]
func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([]*domain.ApplicationWithTokens, error) { func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([]*domain.ApplicationWithTokens, error) {
return c.service.GetByServiceId(ctx, req.Id) return c.service.GetByServiceId(ctx, req.Id)
@@ -96,7 +102,7 @@ func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {array} domain.DomainWithService // @Success 200 {array} domain.DomainWithService
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/get_system_tree [POST] // @Router /application/get_system_tree [POST]
func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithService, error) { func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithService, error) {
return c.service.SystemTree(ctx, domain.DefaultSystemId) return c.service.SystemTree(ctx, domain.DefaultSystemId)
@@ -111,20 +117,34 @@ func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithSer
// @Produce json // @Produce json
// @Param body body domain.ApplicationCreateUpdateRequest true "Объект приложения" // @Param body body domain.ApplicationCreateUpdateRequest true "Объект приложения"
// @Success 200 {object} domain.ApplicationWithTokens // @Success 200 {object} domain.ApplicationWithTokens
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 409 {object} domain.GrpcError // @Failure 409 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/create_update_application [POST] // @Router /application/create_update_application [POST]
func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) { func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
result, err := c.service.CreateUpdate(ctx, req) result, err := c.service.CreateUpdate(ctx, req)
switch { switch {
case errors.Is(err, domain.ErrAppGroupNotFound): case errors.Is(err, domain.ErrAppGroupNotFound):
return nil, status.Errorf(codes.InvalidArgument, "service with id %d not found", req.ServiceId) return nil, apierrors.NewBusinessError(
domain.ErrCodeAppGroupNotFound,
fmt.Sprintf("service with id %d not found", req.ServiceId),
err,
)
case errors.Is(err, domain.ErrApplicationDuplicateName): case errors.Is(err, domain.ErrApplicationDuplicateName):
return nil, status.Errorf(codes.AlreadyExists, "application with name %s already exists", req.Name) return nil, apierrors.New(
codes.AlreadyExists,
domain.ErrCodeApplicationDuplicateName,
fmt.Sprintf("application with name %s already exists", req.Name),
err,
)
case errors.Is(err, domain.ErrApplicationNotFound): case errors.Is(err, domain.ErrApplicationNotFound):
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.Id) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeApplicationNotFound,
fmt.Sprintf("application with id %d not found", req.Id),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -141,12 +161,13 @@ func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
// @Produce json // @Produce json
// @Param body body []integer false "Массив идентификаторов приложений" // @Param body body []integer false "Массив идентификаторов приложений"
// @Success 200 {object} domain.DeleteResponse // @Success 200 {object} domain.DeleteResponse
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/delete_applications [POST] // @Router /application/delete_applications [POST]
func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) { func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
if len(req) == 0 { if len(req) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "At least one id are required") return nil, apierrors.NewBusinessError(domain.ErrCodeInvalidRequest,
"At least one id are required", errors.New("invalid id count"))
} }
result, err := c.service.Delete(ctx, req) result, err := c.service.Delete(ctx, req)
@@ -167,7 +188,7 @@ func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteRespo
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} integer // @Success 200 {object} integer
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/next_id [POST] // @Router /application/next_id [POST]
func (c Application) NextId(ctx context.Context) (int, error) { func (c Application) NextId(ctx context.Context) (int, error) {
return c.service.NextId(ctx) return c.service.NextId(ctx)
@@ -181,7 +202,7 @@ func (c Application) NextId(ctx context.Context) (int, error) {
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {array} domain.Application // @Success 200 {array} domain.Application
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/get_all [POST] // @Router /application/get_all [POST]
func (c Application) GetAll(ctx context.Context) ([]domain.Application, error) { func (c Application) GetAll(ctx context.Context) ([]domain.Application, error) {
return c.service.GetAll(ctx) return c.service.GetAll(ctx)
@@ -196,19 +217,33 @@ func (c Application) GetAll(ctx context.Context) ([]domain.Application, error) {
// @Produce json // @Produce json
// @Param body body domain.CreateApplicationRequest true "Объект приложения" // @Param body body domain.CreateApplicationRequest true "Объект приложения"
// @Success 200 {object} domain.ApplicationWithTokens // @Success 200 {object} domain.ApplicationWithTokens
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 409 {object} domain.GrpcError // @Failure 409 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /application/create_application [POST] // @Router /application/create_application [POST]
func (c Application) Create(ctx context.Context, req domain.CreateApplicationRequest) (*domain.ApplicationWithTokens, error) { func (c Application) Create(ctx context.Context, req domain.CreateApplicationRequest) (*domain.ApplicationWithTokens, error) {
result, err := c.service.Create(ctx, req) result, err := c.service.Create(ctx, req)
switch { switch {
case errors.Is(err, domain.ErrAppGroupNotFound): case errors.Is(err, domain.ErrAppGroupNotFound):
return nil, status.Errorf(codes.InvalidArgument, "application group with id %d not found", req.ApplicationGroupId) return nil, apierrors.NewBusinessError(
domain.ErrCodeAppGroupNotFound,
fmt.Sprintf("application group with id %d not found", req.ApplicationGroupId),
err,
)
case errors.Is(err, domain.ErrApplicationDuplicateName): case errors.Is(err, domain.ErrApplicationDuplicateName):
return nil, status.Errorf(codes.AlreadyExists, "application with name %s already exists", req.Name) return nil, apierrors.New(
codes.AlreadyExists,
domain.ErrCodeApplicationDuplicateName,
fmt.Sprintf("application with name %s already exists", req.Name),
err,
)
case errors.Is(err, domain.ErrApplicationDuplicateId): case errors.Is(err, domain.ErrApplicationDuplicateId):
return nil, status.Errorf(codes.AlreadyExists, "application with id %d already exists", req.Id) return nil, apierrors.New(
codes.AlreadyExists,
domain.ErrCodeApplicationDuplicateId,
fmt.Sprintf("application with id %d already exists", req.Id),
err,
)
default: default:
return result, err return result, err
} }
+35 -13
View File
@@ -2,11 +2,13 @@ package controller
import ( import (
"context" "context"
"fmt"
"isp-system-service/domain"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/grpc/apierrors"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"isp-system-service/domain"
) )
type DomainService interface { type DomainService interface {
@@ -35,14 +37,19 @@ func NewDomain(service DomainService) Domain {
// @Produce json // @Produce json
// @Param body body domain.Identity true "Идентификатор домена" // @Param body body domain.Identity true "Идентификатор домена"
// @Success 200 {object} domain.Domain // @Success 200 {object} domain.Domain
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /domain/get_domain_by_id [POST] // @Router /domain/get_domain_by_id [POST]
func (c Domain) GetById(ctx context.Context, req domain.Identity) (*domain.Domain, error) { func (c Domain) GetById(ctx context.Context, req domain.Identity) (*domain.Domain, error) {
result, err := c.service.GetById(ctx, req.Id) result, err := c.service.GetById(ctx, req.Id)
switch { switch {
case errors.Is(err, domain.ErrDomainNotFound): case errors.Is(err, domain.ErrDomainNotFound):
return nil, status.Errorf(codes.NotFound, "domain with id %d not found", req.Id) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeDomainNotFound,
fmt.Sprintf("domain with id %d not found", req.Id),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -59,7 +66,7 @@ func (c Domain) GetById(ctx context.Context, req domain.Identity) (*domain.Domai
// @Produce json // @Produce json
// @Param body body integer false "Идентификатор системы" // @Param body body integer false "Идентификатор системы"
// @Success 200 {array} domain.Domain // @Success 200 {array} domain.Domain
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /domain/get_domains_by_system_id [POST] // @Router /domain/get_domains_by_system_id [POST]
func (c Domain) GetBySystemId(ctx context.Context) ([]domain.Domain, error) { func (c Domain) GetBySystemId(ctx context.Context) ([]domain.Domain, error) {
return c.service.GetBySystemId(ctx, domain.DefaultSystemId) return c.service.GetBySystemId(ctx, domain.DefaultSystemId)
@@ -74,17 +81,31 @@ func (c Domain) GetBySystemId(ctx context.Context) ([]domain.Domain, error) {
// @Produce json // @Produce json
// @Param body body domain.DomainCreateUpdateRequest true "Объект домена" // @Param body body domain.DomainCreateUpdateRequest true "Объект домена"
// @Success 200 {object} domain.Domain // @Success 200 {object} domain.Domain
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /domain/create_update_domain [POST] // @Router /domain/create_update_domain [POST]
func (c Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateRequest) (*domain.Domain, error) { func (c Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateRequest) (*domain.Domain, error) {
result, err := c.service.CreateUpdate(ctx, req, domain.DefaultSystemId) result, err := c.service.CreateUpdate(ctx, req, domain.DefaultSystemId)
switch { switch {
case errors.Is(err, domain.ErrSystemNotFound): case errors.Is(err, domain.ErrSystemNotFound):
return nil, status.Errorf(codes.InvalidArgument, "system with id %d not found", domain.DefaultSystemId) return nil, apierrors.NewBusinessError(
domain.ErrCodeSystemNotFound,
fmt.Sprintf("system with id %d not found", domain.DefaultSystemId),
err,
)
case errors.Is(err, domain.ErrDomainNotFound): case errors.Is(err, domain.ErrDomainNotFound):
return nil, status.Errorf(codes.NotFound, "domain with id %d not found", req.Id) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeDomainNotFound,
fmt.Sprintf("domain with id %d not found", req.Id),
err,
)
case errors.Is(err, domain.ErrDomainDuplicateName): case errors.Is(err, domain.ErrDomainDuplicateName):
return nil, status.Errorf(codes.AlreadyExists, "domain with name %s already exists", req.Name) return nil, apierrors.New(
codes.AlreadyExists,
domain.ErrCodeDomainDuplicateName,
fmt.Sprintf("domain with name %s already exists", req.Name),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -101,12 +122,13 @@ func (c Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
// @Produce json // @Produce json
// @Param body body []integer false "Массив идентификаторов доменов" // @Param body body []integer false "Массив идентификаторов доменов"
// @Success 200 {object} domain.DeleteResponse // @Success 200 {object} domain.DeleteResponse
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /domain/delete_domains [POST] // @Router /domain/delete_domains [POST]
func (c Domain) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) { func (c Domain) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
if len(req) == 0 { if len(req) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "at least one id are required") return nil, apierrors.NewBusinessError(domain.ErrCodeInvalidRequest,
"At least one id are required", errors.New("invalid id count"))
} }
result, err := c.service.Delete(ctx, req) result, err := c.service.Delete(ctx, req)
+2 -2
View File
@@ -31,7 +31,7 @@ func NewSecure(service SecureService) Secure {
// @Produce json // @Produce json
// @Param body body domain.AuthenticateRequest true "Тело запроса" // @Param body body domain.AuthenticateRequest true "Тело запроса"
// @Success 200 {array} domain.AuthenticateResponse // @Success 200 {array} domain.AuthenticateResponse
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /secure/authenticate [POST] // @Router /secure/authenticate [POST]
func (c Secure) Authenticate(ctx context.Context, req domain.AuthenticateRequest) (*domain.AuthenticateResponse, error) { func (c Secure) Authenticate(ctx context.Context, req domain.AuthenticateRequest) (*domain.AuthenticateResponse, error) {
result, err := c.service.Authenticate(ctx, req.Token) result, err := c.service.Authenticate(ctx, req.Token)
@@ -65,7 +65,7 @@ func (c Secure) Authenticate(ctx context.Context, req domain.AuthenticateRequest
// @Produce json // @Produce json
// @Param body body domain.AuthorizeRequest true "Тело запрос" // @Param body body domain.AuthorizeRequest true "Тело запрос"
// @Success 200 {array} domain.AuthorizeResponse // @Success 200 {array} domain.AuthorizeResponse
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /secure/authorize [POST] // @Router /secure/authorize [POST]
func (c Secure) Authorize(ctx context.Context, req domain.AuthorizeRequest) (*domain.AuthorizeResponse, error) { func (c Secure) Authorize(ctx context.Context, req domain.AuthorizeRequest) (*domain.AuthorizeResponse, error) {
result, err := c.service.Authorize(ctx, req.ApplicationId, req.Endpoint) result, err := c.service.Authorize(ctx, req.ApplicationId, req.Endpoint)
+37 -16
View File
@@ -2,12 +2,13 @@ package controller
import ( import (
"context" "context"
"fmt"
"isp-system-service/domain" "isp-system-service/domain"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/grpc/apierrors"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
type ServiceService interface { type ServiceService interface {
@@ -37,14 +38,19 @@ func NewService(service ServiceService) Service {
// @Produce json // @Produce json
// @Param body body domain.Identity true "Идентификатор сервиса" // @Param body body domain.Identity true "Идентификатор сервиса"
// @Success 200 {object} domain.Service // @Success 200 {object} domain.Service
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /service/get_service_by_id [POST] // @Router /service/get_service_by_id [POST]
func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Service, error) { func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Service, error) {
result, err := c.service.GetById(ctx, req.Id) result, err := c.service.GetById(ctx, req.Id)
switch { switch {
case errors.Is(err, domain.ErrAppGroupNotFound): case errors.Is(err, domain.ErrAppGroupNotFound):
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeAppGroupNotFound,
fmt.Sprintf("service with id %d not found", req.Id),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -61,7 +67,7 @@ func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Serv
// @Produce json // @Produce json
// @Param body body []integer false "Массив идентификаторов сервисов" // @Param body body []integer false "Массив идентификаторов сервисов"
// @Success 200 {array} domain.Service // @Success 200 {array} domain.Service
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /service/get_service [POST] // @Router /service/get_service [POST]
func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) { func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
return c.service.GetByIdList(ctx, req) return c.service.GetByIdList(ctx, req)
@@ -76,7 +82,7 @@ func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
// @Produce json // @Produce json
// @Param body body domain.Identity true "Идентификатор домена" // @Param body body domain.Identity true "Идентификатор домена"
// @Success 200 {array} domain.Service // @Success 200 {array} domain.Service
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /service/get_services_by_domain_id [POST] // @Router /service/get_services_by_domain_id [POST]
func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]domain.Service, error) { func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]domain.Service, error) {
return c.service.GetByDomainId(ctx, req.Id) return c.service.GetByDomainId(ctx, req.Id)
@@ -91,20 +97,34 @@ func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]doma
// @Produce json // @Produce json
// @Param body body domain.ServiceCreateUpdateRequest true "Объект сервиса" // @Param body body domain.ServiceCreateUpdateRequest true "Объект сервиса"
// @Success 200 {object} domain.Service // @Success 200 {object} domain.Service
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 404 {object} domain.GrpcError // @Failure 404 {object} apierrors.Error
// @Failure 409 {object} domain.GrpcError // @Failure 409 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /service/create_update_service [POST] // @Router /service/create_update_service [POST]
func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error) { func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error) {
result, err := c.service.CreateUpdate(ctx, req) result, err := c.service.CreateUpdate(ctx, req)
switch { switch {
case errors.Is(err, domain.ErrDomainNotFound): case errors.Is(err, domain.ErrDomainNotFound):
return nil, status.Errorf(codes.InvalidArgument, "domain with id %d not found", req.DomainId) return nil, apierrors.NewBusinessError(
domain.ErrCodeDomainNotFound,
fmt.Sprintf("domain with id %d not found", req.DomainId),
err,
)
case errors.Is(err, domain.ErrAppGroupNotFound): case errors.Is(err, domain.ErrAppGroupNotFound):
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeAppGroupNotFound,
fmt.Sprintf("service with id %d not found", req.Id),
err,
)
case errors.Is(err, domain.ErrAppGroupDuplicateName): case errors.Is(err, domain.ErrAppGroupDuplicateName):
return nil, status.Errorf(codes.AlreadyExists, "service with name %s already exists", req.Name) return nil, apierrors.New(
codes.AlreadyExists,
domain.ErrCodeAppGroupNotFound,
fmt.Sprintf("service with name %s already exists", req.Name),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -121,12 +141,13 @@ func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdat
// @Produce json // @Produce json
// @Param body body []integer true "Массив идентификаторов сервисов" // @Param body body []integer true "Массив идентификаторов сервисов"
// @Success 200 {object} domain.DeleteResponse // @Success 200 {object} domain.DeleteResponse
// @Failure 400 {object} domain.GrpcError // @Failure 400 {object} apierrors.Error
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /service/delete_service [POST] // @Router /service/delete_service [POST]
func (c Service) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) { func (c Service) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
if len(req) == 0 { if len(req) == 0 {
return nil, status.Error(codes.InvalidArgument, "at least one id are required") return nil, apierrors.NewBusinessError(domain.ErrCodeInvalidRequest,
"At least one id are required", errors.New("invalid id count"))
} }
result, err := c.service.Delete(ctx, req) result, err := c.service.Delete(ctx, req)
+24 -8
View File
@@ -2,12 +2,13 @@ package controller
import ( import (
"context" "context"
"fmt"
"isp-system-service/domain" "isp-system-service/domain"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/grpc/apierrors"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
type TokenService interface { type TokenService interface {
@@ -36,7 +37,7 @@ func NewToken(service TokenService) Token {
// @Produce json // @Produce json
// @Param body body domain.Identity true "Идентификатор приложения" // @Param body body domain.Identity true "Идентификатор приложения"
// @Success 200 {array} entity.Token // @Success 200 {array} entity.Token
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /token/get_tokens_by_app_id [POST] // @Router /token/get_tokens_by_app_id [POST]
func (c Token) GetByAppId(ctx context.Context, req domain.Identity) ([]domain.Token, error) { func (c Token) GetByAppId(ctx context.Context, req domain.Identity) ([]domain.Token, error) {
return c.service.GetByAppId(ctx, req.Id) return c.service.GetByAppId(ctx, req.Id)
@@ -51,17 +52,32 @@ func (c Token) GetByAppId(ctx context.Context, req domain.Identity) ([]domain.To
// @Produce json // @Produce json
// @Param body body domain.TokenCreateRequest true "Объект создания токена" // @Param body body domain.TokenCreateRequest true "Объект создания токена"
// @Success 200 {object} domain.ApplicationWithTokens // @Success 200 {object} domain.ApplicationWithTokens
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /token/create_token [POST] // @Router /token/create_token [POST]
func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*domain.ApplicationWithTokens, error) { func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*domain.ApplicationWithTokens, error) {
result, err := c.service.Create(ctx, req) result, err := c.service.Create(ctx, req)
switch { switch {
case errors.Is(err, domain.ErrApplicationNotFound): case errors.Is(err, domain.ErrApplicationNotFound):
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.AppId) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeApplicationNotFound,
fmt.Sprintf("application with id %d not found", req.AppId),
err,
)
case errors.Is(err, domain.ErrAppGroupNotFound): case errors.Is(err, domain.ErrAppGroupNotFound):
return nil, status.Errorf(codes.NotFound, "service for app_id id %d not found", req.AppId) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeAppGroupNotFound,
fmt.Sprintf("service for app_id id %d not found", req.AppId),
err,
)
case errors.Is(err, domain.ErrDomainNotFound): case errors.Is(err, domain.ErrDomainNotFound):
return nil, status.Errorf(codes.NotFound, "domain for app_id %d not found", req.AppId) return nil, apierrors.New(
codes.NotFound,
domain.ErrCodeDomainNotFound,
fmt.Sprintf("domain for app_id id %d not found", req.AppId),
err,
)
case err != nil: case err != nil:
return nil, err return nil, err
default: default:
@@ -78,7 +94,7 @@ func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
// @Produce json // @Produce json
// @Param body body domain.TokenRevokeRequest true "Объект отзыва токенов" // @Param body body domain.TokenRevokeRequest true "Объект отзыва токенов"
// @Success 200 {object} domain.ApplicationWithTokens // @Success 200 {object} domain.ApplicationWithTokens
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /token/revoke_tokens [POST] // @Router /token/revoke_tokens [POST]
func (c Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*domain.ApplicationWithTokens, error) { func (c Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*domain.ApplicationWithTokens, error) {
return c.service.Revoke(ctx, req) return c.service.Revoke(ctx, req)
@@ -93,7 +109,7 @@ func (c Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*doma
// @Produce json // @Produce json
// @Param body body domain.Identity true "Идентификатор приложения" // @Param body body domain.Identity true "Идентификатор приложения"
// @Success 200 {object} domain.DeleteResponse // @Success 200 {object} domain.DeleteResponse
// @Failure 500 {object} domain.GrpcError // @Failure 500 {object} apierrors.Error
// @Router /token/revoke_tokens_for_app [POST] // @Router /token/revoke_tokens_for_app [POST]
func (c Token) RevokeForApp(ctx context.Context, req domain.Identity) (*domain.DeleteResponse, error) { func (c Token) RevokeForApp(ctx context.Context, req domain.Identity) (*domain.DeleteResponse, error) {
return c.service.RevokeByAppId(ctx, req.Id) return c.service.RevokeByAppId(ctx, req.Id)
+77 -73
View File
@@ -1,5 +1,15 @@
basePath: /api/system basePath: /api/system
definitions: definitions:
apierrors.Error:
properties:
details:
additionalProperties: true
type: object
errorCode:
type: integer
errorMessage:
type: string
type: object
domain.AccessListSetListRequest: domain.AccessListSetListRequest:
properties: properties:
appId: appId:
@@ -172,6 +182,7 @@ definitions:
type: string type: string
required: required:
- applicationGroupId - applicationGroupId
- id
- name - name
- type - type
type: object type: object
@@ -219,16 +230,6 @@ definitions:
$ref: '#/definitions/domain.ServiceWithApps' $ref: '#/definitions/domain.ServiceWithApps'
type: array type: array
type: object type: object
domain.GrpcError:
properties:
details:
items: {}
type: array
errorCode:
type: string
errorMessage:
type: string
type: object
domain.IdListRequest: domain.IdListRequest:
properties: properties:
idList: idList:
@@ -343,13 +344,16 @@ definitions:
properties: properties:
description: description:
type: string type: string
id:
type: integer
name: name:
type: string type: string
newId:
type: integer
oldId:
type: integer
required: required:
- id
- name - name
- newId
- oldId
type: object type: object
entity.Token: entity.Token:
properties: properties:
@@ -395,11 +399,11 @@ paths:
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить список доступности методов для приложения summary: Получить список доступности методов для приложения
tags: tags:
- accessList - accessList
@@ -427,11 +431,11 @@ paths:
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Настроить доступность списка методов для приложения summary: Настроить доступность списка методов для приложения
tags: tags:
- accessList - accessList
@@ -456,11 +460,11 @@ paths:
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Настроить доступность метода для приложения summary: Настроить доступность метода для приложения
tags: tags:
- accessList - accessList
@@ -487,15 +491,15 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"409": "409":
description: Conflict description: Conflict
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Создать приложение summary: Создать приложение
tags: tags:
- application - application
@@ -522,19 +526,19 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"409": "409":
description: Conflict description: Conflict
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Создать/обновить приложение summary: Создать/обновить приложение
tags: tags:
- application - application
@@ -562,11 +566,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Удалить приложения summary: Удалить приложения
tags: tags:
- application - application
@@ -587,7 +591,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить список приложений summary: Получить список приложений
tags: tags:
- application - application
@@ -613,15 +617,15 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить приложение по идентификатору summary: Получить приложение по идентификатору
tags: tags:
- application - application
@@ -650,7 +654,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить список приложений summary: Получить список приложений
tags: tags:
- application - application
@@ -678,7 +682,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить список приложений по идентификатору сервиса summary: Получить список приложений по идентификатору сервиса
tags: tags:
- application - application
@@ -699,7 +703,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Метод получения системного дерева summary: Метод получения системного дерева
tags: tags:
- application - application
@@ -718,7 +722,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить следующий идентификатор приложения summary: Получить следующий идентификатор приложения
tags: tags:
- application - application
@@ -745,19 +749,19 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"409": "409":
description: Conflict description: Conflict
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Обновить приложение summary: Обновить приложение
tags: tags:
- application - application
@@ -783,15 +787,15 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"409": "409":
description: Conflict description: Conflict
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Создать группу приложений summary: Создать группу приложений
tags: tags:
- application_group - application_group
@@ -818,11 +822,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Удалить группы приложений summary: Удалить группы приложений
tags: tags:
- application_group - application_group
@@ -850,11 +854,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить группы приложений по списку идентификаторов summary: Получить группы приложений по списку идентификаторов
tags: tags:
- application_group - application_group
@@ -881,19 +885,19 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"409": "409":
description: Conflict description: Conflict
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Обновить группу приложений summary: Обновить группу приложений
tags: tags:
- application_group - application_group
@@ -920,7 +924,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Создать/обновить домен summary: Создать/обновить домен
tags: tags:
- domain - domain
@@ -948,11 +952,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Удаление доменов summary: Удаление доменов
tags: tags:
- domain - domain
@@ -978,11 +982,11 @@ paths:
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить домен по идентификатору summary: Получить домен по идентификатору
tags: tags:
- domain - domain
@@ -1009,7 +1013,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить домены по идентификатору системы summary: Получить домены по идентификатору системы
tags: tags:
- domain - domain
@@ -1037,7 +1041,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Метод аутентификации токена summary: Метод аутентификации токена
tags: tags:
- secure - secure
@@ -1065,7 +1069,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Метод авторизации приложения summary: Метод авторизации приложения
tags: tags:
- secure - secure
@@ -1092,19 +1096,19 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"409": "409":
description: Conflict description: Conflict
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Создать/обновить сервис summary: Создать/обновить сервис
tags: tags:
- service - service
@@ -1133,11 +1137,11 @@ paths:
"400": "400":
description: Bad Request description: Bad Request
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Удалить сервисы summary: Удалить сервисы
tags: tags:
- service - service
@@ -1166,7 +1170,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить список сервисов summary: Получить список сервисов
tags: tags:
- service - service
@@ -1192,11 +1196,11 @@ paths:
"404": "404":
description: Not Found description: Not Found
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить сервис по идентификатору summary: Получить сервис по идентификатору
tags: tags:
- service - service
@@ -1224,7 +1228,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить список сервисов по идентификатору домена summary: Получить список сервисов по идентификатору домена
tags: tags:
- service - service
@@ -1250,7 +1254,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Создать токен summary: Создать токен
tags: tags:
- token - token
@@ -1278,7 +1282,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Получить токены по идентификатору приложения summary: Получить токены по идентификатору приложения
tags: tags:
- token - token
@@ -1304,7 +1308,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Отозвать токены summary: Отозвать токены
tags: tags:
- token - token
@@ -1331,7 +1335,7 @@ paths:
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/domain.GrpcError' $ref: '#/definitions/apierrors.Error'
summary: Отозвать токены для приложения summary: Отозвать токены для приложения
tags: tags:
- token - token
+9 -2
View File
@@ -5,11 +5,18 @@ import (
) )
const ( const (
ErrCodeInvalidRequest = 600 ErrCodeInvalidRequest = 600
ErrCodeAppGroupNotFound = 601
ErrCodeApplicationNotFound = 602 ErrCodeApplicationNotFound = 602
ErrCodeApplicationDuplicateName = 603 ErrCodeApplicationDuplicateName = 603
ErrCodeApplicationDuplicateId = 604 ErrCodeApplicationDuplicateId = 604
ErrCodeAppGroupNotFound = 605
ErrCodeAppGroupDuplicateName = 606
ErrCodeSystemNotFound = 607
ErrCodeDomainNotFound = 608
ErrCodeDomainDuplicateName = 609
) )
var ( var (
-7
View File
@@ -1,7 +0,0 @@
package domain
type GrpcError struct {
ErrorMessage string `json:"errorMessage"`
ErrorCode string `json:"errorCode"`
Details []interface{} `json:"details"`
}
+10 -14
View File
@@ -11,13 +11,12 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/txix-open/isp-kit/dbx" "github.com/txix-open/isp-kit/dbx"
"github.com/txix-open/isp-kit/grpc/apierrors"
"github.com/txix-open/isp-kit/grpc/client" "github.com/txix-open/isp-kit/grpc/client"
"github.com/txix-open/isp-kit/test" "github.com/txix-open/isp-kit/test"
"github.com/txix-open/isp-kit/test/dbt" "github.com/txix-open/isp-kit/test/dbt"
"github.com/txix-open/isp-kit/test/fake" "github.com/txix-open/isp-kit/test/fake"
"github.com/txix-open/isp-kit/test/grpct" "github.com/txix-open/isp-kit/test/grpct"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
func TestApplicationGroupSuite(t *testing.T) { func TestApplicationGroupSuite(t *testing.T) {
@@ -171,10 +170,9 @@ func (s *AppGroupSuite) TestCreate_AppGroupNameNotUnique() {
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
JsonResponseBody(&result). JsonResponseBody(&result).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeAppGroupDuplicateName, apiError.ErrorCode)
s.Require().Equal(codes.AlreadyExists, statusErr.Code())
} }
func (s *AppGroupSuite) TestUpdate_HappyPath() { func (s *AppGroupSuite) TestUpdate_HappyPath() {
@@ -213,10 +211,9 @@ func (s *AppGroupSuite) TestUpdate_AppGroupNameNotUnique() {
err := s.api.Invoke("system/application_group/update"). err := s.api.Invoke("system/application_group/update").
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeAppGroupDuplicateName, apiError.ErrorCode)
s.Require().Equal(codes.AlreadyExists, statusErr.Code())
} }
func (s *AppGroupSuite) TestUpdate_AppGroupNotFound() { func (s *AppGroupSuite) TestUpdate_AppGroupNotFound() {
@@ -228,10 +225,9 @@ func (s *AppGroupSuite) TestUpdate_AppGroupNotFound() {
err := s.api.Invoke("system/application_group/update"). err := s.api.Invoke("system/application_group/update").
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeAppGroupNotFound, apiError.ErrorCode)
s.Require().Equal(codes.NotFound, statusErr.Code())
} }
func (s *AppGroupSuite) TestDeleteList() { func (s *AppGroupSuite) TestDeleteList() {
+19 -26
View File
@@ -11,13 +11,12 @@ import (
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/txix-open/isp-kit/dbx" "github.com/txix-open/isp-kit/dbx"
"github.com/txix-open/isp-kit/grpc/apierrors"
"github.com/txix-open/isp-kit/grpc/client" "github.com/txix-open/isp-kit/grpc/client"
"github.com/txix-open/isp-kit/test" "github.com/txix-open/isp-kit/test"
"github.com/txix-open/isp-kit/test/dbt" "github.com/txix-open/isp-kit/test/dbt"
"github.com/txix-open/isp-kit/test/fake" "github.com/txix-open/isp-kit/test/fake"
"github.com/txix-open/isp-kit/test/grpct" "github.com/txix-open/isp-kit/test/grpct"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
) )
func TestApplicationSuite(t *testing.T) { func TestApplicationSuite(t *testing.T) {
@@ -104,10 +103,9 @@ func (s *ApplicationSuite) TestCreate_AppGroupNotFound() {
err := s.api.Invoke("system/application/create_application"). err := s.api.Invoke("system/application/create_application").
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeAppGroupNotFound, apiError.ErrorCode)
s.Require().Equal(codes.InvalidArgument, statusErr.Code())
} }
func (s *ApplicationSuite) TestCreate_ApplicationNameNotUniqueInAppGroup() { func (s *ApplicationSuite) TestCreate_ApplicationNameNotUniqueInAppGroup() {
@@ -122,10 +120,9 @@ func (s *ApplicationSuite) TestCreate_ApplicationNameNotUniqueInAppGroup() {
err := s.api.Invoke("system/application/create_application"). err := s.api.Invoke("system/application/create_application").
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeApplicationDuplicateName, apiError.ErrorCode)
s.Require().Equal(codes.AlreadyExists, statusErr.Code())
} }
func (s *ApplicationSuite) TestCreate_ApplicationIdNotUnique() { func (s *ApplicationSuite) TestCreate_ApplicationIdNotUnique() {
@@ -140,10 +137,9 @@ func (s *ApplicationSuite) TestCreate_ApplicationIdNotUnique() {
err := s.api.Invoke("system/application/create_application"). err := s.api.Invoke("system/application/create_application").
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeApplicationDuplicateId, apiError.ErrorCode)
s.Require().Equal(codes.AlreadyExists, statusErr.Code())
} }
func (s *ApplicationSuite) TestUpdate_HappyPath() { func (s *ApplicationSuite) TestUpdate_HappyPath() {
@@ -209,10 +205,9 @@ func (s *ApplicationSuite) TestUpdate_ApplicationNameNotUniqueInAppGroup() {
err := s.api.Invoke("system/application/update_application"). err := s.api.Invoke("system/application/update_application").
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeApplicationDuplicateName, apiError.ErrorCode)
s.Require().Equal(codes.AlreadyExists, statusErr.Code())
} }
func (s *ApplicationSuite) TestUpdate_AppIdNotUnique() { func (s *ApplicationSuite) TestUpdate_AppIdNotUnique() {
@@ -227,10 +222,9 @@ func (s *ApplicationSuite) TestUpdate_AppIdNotUnique() {
err := s.api.Invoke("system/application/update_application"). err := s.api.Invoke("system/application/update_application").
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeApplicationDuplicateId, apiError.ErrorCode)
s.Require().Equal(codes.AlreadyExists, statusErr.Code())
} }
func (s *ApplicationSuite) TestUpdate_AppNotFound() { func (s *ApplicationSuite) TestUpdate_AppNotFound() {
@@ -244,10 +238,9 @@ func (s *ApplicationSuite) TestUpdate_AppNotFound() {
err := s.api.Invoke("system/application/update_application"). err := s.api.Invoke("system/application/update_application").
JsonRequestBody(apiReq). JsonRequestBody(apiReq).
Do(s.T().Context()) Do(s.T().Context())
statusErr, ok := status.FromError(err) apiError := apierrors.FromError(err)
s.Require().True(ok) s.Require().NotNil(apiError)
s.Require().NotNil(statusErr) s.Require().Equal(domain.ErrCodeApplicationNotFound, apiError.ErrorCode)
s.Require().Equal(codes.NotFound, statusErr.Code())
} }
func (s *ApplicationSuite) createAppGroup() *entity.AppGroup { func (s *ApplicationSuite) createAppGroup() *entity.AppGroup {