MSP-8974 fix tests for http

This commit is contained in:
chashintv committed 2026-11-23 12:58:51 +03:00
1 parent fa8bc6c1b7
commit 3e707244dd
26 files changed
+289 -1313

No files matched your search

+11 -12
View File
@@ -2,13 +2,12 @@ package controller
import (
"context"
"net/http"
"isp-admin-service/domain"
"github.com/txix-open/isp-kit/errors"
"github.com/txix-open/isp-kit/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/txix-open/isp-kit/http/apierrors"
)
type roleService interface {
@@ -62,8 +61,8 @@ func (u Role) All(ctx context.Context, req domain.RoleAllRequest) ([]domain.Role
// @Failure 409 {object} domain.GrpcError "Роль с указанным именем уже существует"
// @Failure 500 {object} domain.GrpcError
// @Router /role/create [POST]
func (u Role) CreateRole(ctx context.Context, authData grpc.AuthData, req domain.CreateRoleRequest) (*domain.Role, error) {
adminId, err := getAdminId(authData)
func (u Role) CreateRole(ctx context.Context, req domain.CreateRoleRequest, r *http.Request) (*domain.Role, error) {
adminId, err := getAdminId(r)
if err != nil {
return nil, err
}
@@ -71,7 +70,7 @@ func (u Role) CreateRole(ctx context.Context, authData grpc.AuthData, req domain
role, err := u.roleService.Create(ctx, req, adminId)
switch {
case errors.Is(err, domain.ErrAlreadyExists):
return nil, status.Error(codes.AlreadyExists, "role with current name already exists")
return nil, apierrors.New(http.StatusConflict, domain.ErrAlreadyExistsCode, err.Error(), err)
case err != nil:
return nil, errors.WithMessage(err, "create role")
default:
@@ -92,8 +91,8 @@ func (u Role) CreateRole(ctx context.Context, authData grpc.AuthData, req domain
// @Failure 409 {object} domain.GrpcError "Роль с указанным именем уже существует"
// @Failure 500 {object} domain.GrpcError
// @Router /role/update [POST]
func (u Role) UpdateRole(ctx context.Context, authData grpc.AuthData, req domain.UpdateRoleRequest) (*domain.Role, error) {
adminId, err := getAdminId(authData)
func (u Role) UpdateRole(ctx context.Context, req domain.UpdateRoleRequest, r *http.Request) (*domain.Role, error) {
adminId, err := getAdminId(r)
if err != nil {
return nil, err
}
@@ -101,9 +100,9 @@ func (u Role) UpdateRole(ctx context.Context, authData grpc.AuthData, req domain
result, err := u.roleService.Update(ctx, req, adminId)
switch {
case errors.Is(err, domain.ErrNotFound):
return nil, status.Error(codes.NotFound, "role not found")
return nil, apierrors.New(http.StatusNotFound, domain.ErrNotFoundCode, err.Error(), err)
case errors.Is(err, domain.ErrAlreadyExists):
return nil, status.Error(codes.AlreadyExists, "role with current name already exists")
return nil, apierrors.New(http.StatusConflict, domain.ErrAlreadyExistsCode, err.Error(), err)
case err != nil:
return nil, errors.WithMessage(err, "update role")
default:
@@ -123,8 +122,8 @@ func (u Role) UpdateRole(ctx context.Context, authData grpc.AuthData, req domain
// @Failure 400 {object} domain.GrpcError "Невалидное тело запроса"
// @Failure 500 {object} domain.GrpcError
// @Router /role/delete [POST]
func (u Role) DeleteRole(ctx context.Context, authData grpc.AuthData, req domain.DeleteRoleRequest) error {
adminId, err := getAdminId(authData)
func (u Role) DeleteRole(ctx context.Context, req domain.DeleteRoleRequest, r *http.Request) error {
adminId, err := getAdminId(r)
if err != nil {
return err
}