MSP-5186 Use apierrrors.Error
This commit is contained in:
1 parent
3b43e7875d
commit
199d576956
12 files changed
+333
-213
No files matched your search
+28
-11
@@ -2,11 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type AccessListService interface {
|
||||
@@ -34,14 +36,19 @@ func NewAccessList(service AccessListService) AccessList {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity false "идентификатор приложения"
|
||||
// @Success 200 {array} domain.MethodInfo "список доступности методов"
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /access_list/get_by_id [POST]
|
||||
func (c AccessList) GetById(ctx context.Context, req domain.Identity) ([]domain.MethodInfo, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
switch {
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -58,14 +65,19 @@ func (c AccessList) GetById(ctx context.Context, req domain.Identity) ([]domain.
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListSetOneRequest false "объект для настройки доступа"
|
||||
// @Success 200 {object} domain.AccessListSetOneResponse "количество измененных строк"
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /access_list/set_one [POST]
|
||||
func (c AccessList) SetOne(ctx context.Context, req domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error) {
|
||||
result, err := c.service.SetOne(ctx, req)
|
||||
switch {
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -82,14 +94,19 @@ func (c AccessList) SetOne(ctx context.Context, req domain.AccessListSetOneReque
|
||||
// @Produce json
|
||||
// @Param body body domain.AccessListSetListRequest false "объект настройки доступа"
|
||||
// @Success 200 {array} domain.MethodInfo "список доступности методов"
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /access_list/set_list [POST]
|
||||
func (c AccessList) SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error) {
|
||||
result, err := c.service.SetList(ctx, req)
|
||||
switch {
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
|
||||
+31
-15
@@ -2,11 +2,12 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type AppGroupService interface {
|
||||
@@ -35,15 +36,20 @@ func NewAppGroup(service AppGroupService) AppGroup {
|
||||
// @Produce json
|
||||
// @Param body body domain.CreateAppGroupRequest true "Объект группы приложений"
|
||||
// @Success 200 {object} domain.AppGroup
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/create [POST]
|
||||
func (c AppGroup) Create(ctx context.Context, req domain.CreateAppGroupRequest) (*domain.AppGroup, error) {
|
||||
result, err := c.service.Create(ctx, req)
|
||||
switch {
|
||||
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:
|
||||
return result, err
|
||||
}
|
||||
@@ -58,18 +64,28 @@ func (c AppGroup) Create(ctx context.Context, req domain.CreateAppGroupRequest)
|
||||
// @Produce json
|
||||
// @Param body body domain.UpdateAppGroupRequest true "Объект группы приложений"
|
||||
// @Success 200 {object} domain.AppGroup
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/update [POST]
|
||||
func (c AppGroup) Update(ctx context.Context, req domain.UpdateAppGroupRequest) (*domain.AppGroup, error) {
|
||||
result, err := c.service.Update(ctx, req)
|
||||
switch {
|
||||
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):
|
||||
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:
|
||||
return result, err
|
||||
}
|
||||
@@ -84,8 +100,8 @@ func (c AppGroup) Update(ctx context.Context, req domain.UpdateAppGroupRequest)
|
||||
// @Produce json
|
||||
// @Param body body domain.IdListRequest true "список идентификаторов групп приложений"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/delete_list [POST]
|
||||
func (c AppGroup) DeleteList(ctx context.Context, req domain.IdListRequest) (*domain.DeleteResponse, error) {
|
||||
return c.service.DeleteList(ctx, req)
|
||||
@@ -100,8 +116,8 @@ func (c AppGroup) DeleteList(ctx context.Context, req domain.IdListRequest) (*do
|
||||
// @Produce json
|
||||
// @Param body body domain.IdListRequest true "список идентификаторов групп приложений"
|
||||
// @Success 200 {array} domain.AppGroup
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application_group/get_by_id_list [POST]
|
||||
func (c AppGroup) GetByIdList(ctx context.Context, req domain.IdListRequest) ([]domain.AppGroup, error) {
|
||||
return c.service.GetByIdList(ctx, req.IdList)
|
||||
|
||||
+61
-26
@@ -2,12 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type ApplicationService interface {
|
||||
@@ -42,15 +43,20 @@ func NewApplication(service ApplicationService) Application {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_application_by_id [POST]
|
||||
func (c Application) GetById(ctx context.Context, req domain.Identity) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
switch {
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -67,7 +73,7 @@ func (c Application) GetById(ctx context.Context, req domain.Identity) (*domain.
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_applications [POST]
|
||||
func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.ApplicationWithTokens, error) {
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
@@ -82,7 +88,7 @@ func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.Appl
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_applications_by_service_id [POST]
|
||||
func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([]*domain.ApplicationWithTokens, error) {
|
||||
return c.service.GetByServiceId(ctx, req.Id)
|
||||
@@ -96,7 +102,7 @@ func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.DomainWithService
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_system_tree [POST]
|
||||
func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithService, error) {
|
||||
return c.service.SystemTree(ctx, domain.DefaultSystemId)
|
||||
@@ -111,20 +117,34 @@ func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithSer
|
||||
// @Produce json
|
||||
// @Param body body domain.ApplicationCreateUpdateRequest true "Объект приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/create_update_application [POST]
|
||||
func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.CreateUpdate(ctx, req)
|
||||
switch {
|
||||
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):
|
||||
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):
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -141,12 +161,13 @@ func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/delete_applications [POST]
|
||||
func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
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)
|
||||
@@ -167,7 +188,7 @@ func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteRespo
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} integer
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/next_id [POST]
|
||||
func (c Application) NextId(ctx context.Context) (int, error) {
|
||||
return c.service.NextId(ctx)
|
||||
@@ -181,7 +202,7 @@ func (c Application) NextId(ctx context.Context) (int, error) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.Application
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/get_all [POST]
|
||||
func (c Application) GetAll(ctx context.Context) ([]domain.Application, error) {
|
||||
return c.service.GetAll(ctx)
|
||||
@@ -196,19 +217,33 @@ func (c Application) GetAll(ctx context.Context) ([]domain.Application, error) {
|
||||
// @Produce json
|
||||
// @Param body body domain.CreateApplicationRequest true "Объект приложения"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /application/create_application [POST]
|
||||
func (c Application) Create(ctx context.Context, req domain.CreateApplicationRequest) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.Create(ctx, req)
|
||||
switch {
|
||||
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):
|
||||
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):
|
||||
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:
|
||||
return result, err
|
||||
}
|
||||
|
||||
+35
-13
@@ -2,11 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type DomainService interface {
|
||||
@@ -35,14 +37,19 @@ func NewDomain(service DomainService) Domain {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {object} domain.Domain
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /domain/get_domain_by_id [POST]
|
||||
func (c Domain) GetById(ctx context.Context, req domain.Identity) (*domain.Domain, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
switch {
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -59,7 +66,7 @@ func (c Domain) GetById(ctx context.Context, req domain.Identity) (*domain.Domai
|
||||
// @Produce json
|
||||
// @Param body body integer false "Идентификатор системы"
|
||||
// @Success 200 {array} domain.Domain
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /domain/get_domains_by_system_id [POST]
|
||||
func (c Domain) GetBySystemId(ctx context.Context) ([]domain.Domain, error) {
|
||||
return c.service.GetBySystemId(ctx, domain.DefaultSystemId)
|
||||
@@ -74,17 +81,31 @@ func (c Domain) GetBySystemId(ctx context.Context) ([]domain.Domain, error) {
|
||||
// @Produce json
|
||||
// @Param body body domain.DomainCreateUpdateRequest true "Объект домена"
|
||||
// @Success 200 {object} domain.Domain
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /domain/create_update_domain [POST]
|
||||
func (c Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateRequest) (*domain.Domain, error) {
|
||||
result, err := c.service.CreateUpdate(ctx, req, domain.DefaultSystemId)
|
||||
switch {
|
||||
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):
|
||||
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):
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -101,12 +122,13 @@ func (c Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов доменов"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /domain/delete_domains [POST]
|
||||
func (c Domain) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
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)
|
||||
|
||||
@@ -31,7 +31,7 @@ func NewSecure(service SecureService) Secure {
|
||||
// @Produce json
|
||||
// @Param body body domain.AuthenticateRequest true "Тело запроса"
|
||||
// @Success 200 {array} domain.AuthenticateResponse
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /secure/authenticate [POST]
|
||||
func (c Secure) Authenticate(ctx context.Context, req domain.AuthenticateRequest) (*domain.AuthenticateResponse, error) {
|
||||
result, err := c.service.Authenticate(ctx, req.Token)
|
||||
@@ -65,7 +65,7 @@ func (c Secure) Authenticate(ctx context.Context, req domain.AuthenticateRequest
|
||||
// @Produce json
|
||||
// @Param body body domain.AuthorizeRequest true "Тело запрос"
|
||||
// @Success 200 {array} domain.AuthorizeResponse
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /secure/authorize [POST]
|
||||
func (c Secure) Authorize(ctx context.Context, req domain.AuthorizeRequest) (*domain.AuthorizeResponse, error) {
|
||||
result, err := c.service.Authorize(ctx, req.ApplicationId, req.Endpoint)
|
||||
|
||||
+37
-16
@@ -2,12 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type ServiceService interface {
|
||||
@@ -37,14 +38,19 @@ func NewService(service ServiceService) Service {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {object} domain.Service
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /service/get_service_by_id [POST]
|
||||
func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Service, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
switch {
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -61,7 +67,7 @@ func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Serv
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов сервисов"
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /service/get_service [POST]
|
||||
func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
@@ -76,7 +82,7 @@ func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /service/get_services_by_domain_id [POST]
|
||||
func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]domain.Service, error) {
|
||||
return c.service.GetByDomainId(ctx, req.Id)
|
||||
@@ -91,20 +97,34 @@ func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]doma
|
||||
// @Produce json
|
||||
// @Param body body domain.ServiceCreateUpdateRequest true "Объект сервиса"
|
||||
// @Success 200 {object} domain.Service
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 404 {object} apierrors.Error
|
||||
// @Failure 409 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /service/create_update_service [POST]
|
||||
func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error) {
|
||||
result, err := c.service.CreateUpdate(ctx, req)
|
||||
switch {
|
||||
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):
|
||||
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):
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -121,12 +141,13 @@ func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdat
|
||||
// @Produce json
|
||||
// @Param body body []integer true "Массив идентификаторов сервисов"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 400 {object} apierrors.Error
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /service/delete_service [POST]
|
||||
func (c Service) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
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)
|
||||
|
||||
+24
-8
@@ -2,12 +2,13 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"isp-system-service/domain"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type TokenService interface {
|
||||
@@ -36,7 +37,7 @@ func NewToken(service TokenService) Token {
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {array} entity.Token
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /token/get_tokens_by_app_id [POST]
|
||||
func (c Token) GetByAppId(ctx context.Context, req domain.Identity) ([]domain.Token, error) {
|
||||
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
|
||||
// @Param body body domain.TokenCreateRequest true "Объект создания токена"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /token/create_token [POST]
|
||||
func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.Create(ctx, req)
|
||||
switch {
|
||||
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):
|
||||
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):
|
||||
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:
|
||||
return nil, err
|
||||
default:
|
||||
@@ -78,7 +94,7 @@ func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
// @Produce json
|
||||
// @Param body body domain.TokenRevokeRequest true "Объект отзыва токенов"
|
||||
// @Success 200 {object} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /token/revoke_tokens [POST]
|
||||
func (c Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*domain.ApplicationWithTokens, error) {
|
||||
return c.service.Revoke(ctx, req)
|
||||
@@ -93,7 +109,7 @@ func (c Token) Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*doma
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /token/revoke_tokens_for_app [POST]
|
||||
func (c Token) RevokeForApp(ctx context.Context, req domain.Identity) (*domain.DeleteResponse, error) {
|
||||
return c.service.RevokeByAppId(ctx, req.Id)
|
||||
|
||||
Reference in new issue
Block a user