From bed33506f434ba34bd894649025c8babcb486a81 Mon Sep 17 00:00:00 2001 From: Roman Rusakov Date: Tue, 25 Jun 2024 12:55:44 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D0=B1=D1=89=D0=B0=D1=8F=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BA=D0=B0=20Forbidden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.props | 2 +- .../Extensions/ControllerModelResultExtensions.cs | 3 +++ src/ModelResult/Common/CommonErrorCodes.cs | 2 ++ src/ModelResult/Common/CommonErrorMessages.cs | 2 ++ src/ModelResult/Common/CommonErrorResult.cs | 2 ++ src/ModelResult/Common/CommonErrorResultExtensions.cs | 10 ++++++++++ 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index fa03423..ab19dd1 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 1.3.0 + 1.4.0 Byndyusoft.ModelResult Byndyusoft Byndyusoft;ModelResult diff --git a/src/ModelResult.AspNetCore/Extensions/ControllerModelResultExtensions.cs b/src/ModelResult.AspNetCore/Extensions/ControllerModelResultExtensions.cs index f8a366a..0314208 100644 --- a/src/ModelResult.AspNetCore/Extensions/ControllerModelResultExtensions.cs +++ b/src/ModelResult.AspNetCore/Extensions/ControllerModelResultExtensions.cs @@ -27,6 +27,9 @@ private static ActionResult GetErrorResult(ModelResult modelResult) if (modelResult.IsNotFound()) return new NotFoundResult(); + if (modelResult.IsForbidden()) + return new ForbidResult(); + return new BadRequestObjectResult(modelResult.GetError()); } } diff --git a/src/ModelResult/Common/CommonErrorCodes.cs b/src/ModelResult/Common/CommonErrorCodes.cs index b601c1e..a6c2ee4 100644 --- a/src/ModelResult/Common/CommonErrorCodes.cs +++ b/src/ModelResult/Common/CommonErrorCodes.cs @@ -3,5 +3,7 @@ public static class CommonErrorCodes { public static string NotFound => "Common.NotFound"; + + public static string Forbidden => "Common.Forbidden"; } } \ No newline at end of file diff --git a/src/ModelResult/Common/CommonErrorMessages.cs b/src/ModelResult/Common/CommonErrorMessages.cs index d9ba6cb..b97b953 100644 --- a/src/ModelResult/Common/CommonErrorMessages.cs +++ b/src/ModelResult/Common/CommonErrorMessages.cs @@ -3,5 +3,7 @@ public static class CommonErrorMessages { public static string NotFound => "Not found"; + + public static string Forbidden => "Forbidden"; } } \ No newline at end of file diff --git a/src/ModelResult/Common/CommonErrorResult.cs b/src/ModelResult/Common/CommonErrorResult.cs index a8fce18..1d6f57c 100644 --- a/src/ModelResult/Common/CommonErrorResult.cs +++ b/src/ModelResult/Common/CommonErrorResult.cs @@ -5,5 +5,7 @@ public static class CommonErrorResult { public static ErrorModelResult NotFound { get; } = new ErrorModelResult(CommonErrorCodes.NotFound, CommonErrorMessages.NotFound); + + public static ErrorModelResult Forbidden { get; } = new ErrorModelResult(CommonErrorCodes.Forbidden, CommonErrorMessages.Forbidden); } } \ No newline at end of file diff --git a/src/ModelResult/Common/CommonErrorResultExtensions.cs b/src/ModelResult/Common/CommonErrorResultExtensions.cs index 7c2c0b3..bdc0bd6 100644 --- a/src/ModelResult/Common/CommonErrorResultExtensions.cs +++ b/src/ModelResult/Common/CommonErrorResultExtensions.cs @@ -9,9 +9,19 @@ public static bool IsNotFound(this ModelResult modelResult) return modelResult.IsError() && modelResult.GetError().Code == CommonErrorCodes.NotFound; } + public static bool IsForbidden(this ModelResult modelResult) + { + return modelResult.IsError() && modelResult.GetError().Code == CommonErrorCodes.Forbidden; + } + public static bool IsNotFound(this ModelResult modelResult) { return IsNotFound(modelResult.AsSimple()); } + + public static bool IsForbidden(this ModelResult modelResult) + { + return IsForbidden(modelResult.AsSimple()); + } } } \ No newline at end of file