MSP-8974 fix tests for http

This commit is contained in:
chashintv committed 2026-11-19 20:02:12 +03:00
1 parent 82a5de3782
commit 7a36a09fa8
26 files changed
+281 -1305

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 {
@@ -61,8 +60,8 @@ func (u Role) All(ctx context.Context) ([]domain.Role, error) {
// @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
}
@@ -70,7 +69,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:
@@ -91,8 +90,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
}
@@ -100,9 +99,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:
@@ -122,8 +121,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
}