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
+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)
|
||||
|
||||
Reference in new issue
Block a user