From 2b6bff09624e4796afc5e35a509083396626a8a2 Mon Sep 17 00:00:00 2001 From: Romeo Dumitrescu Date: Mon, 14 Oct 2024 10:27:00 +0300 Subject: [PATCH] refactor(Problems): update method calls and improve code readability - Replaced direct method calls with TypedResults class in ProblemExtensions.cs - Improved code readability by adjusting comment indentation and formatting - Updated the documentation comments for better clarity in ProblemException.cs and ProblemExtensions.cs --- .../Problems/ProblemExtensions.cs | 26 +++++++++---------- src/ES.FX/Problems/ProblemException.cs | 6 ++--- src/ES.FX/Problems/ProblemExtensions.cs | 6 ++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/ES.FX.Microsoft.AspNetCore/Problems/ProblemExtensions.cs b/src/ES.FX.Microsoft.AspNetCore/Problems/ProblemExtensions.cs index 1e4eef1..e905230 100644 --- a/src/ES.FX.Microsoft.AspNetCore/Problems/ProblemExtensions.cs +++ b/src/ES.FX.Microsoft.AspNetCore/Problems/ProblemExtensions.cs @@ -2,10 +2,10 @@ using System.Text.Json; using ES.FX.Problems; using JetBrains.Annotations; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.WebUtilities; -using static Microsoft.AspNetCore.Http.TypedResults; using ValidationProblem = ES.FX.Problems.ValidationProblem; namespace ES.FX.Microsoft.AspNetCore.Problems; @@ -32,9 +32,9 @@ public static class ProblemExtensions }; /// - /// Formats a as + /// Formats a as /// - /// The source + /// The source [PublicAPI] public static ProblemDetails AsProblemDetails(this Problem problem) { @@ -72,37 +72,37 @@ public static ProblemDetails AsProblemDetails(this Problem problem) } /// - /// Returns an result with the specified + /// Returns an result with the specified /// [PublicAPI] public static UnprocessableEntity AsUnprocessableEntityResult(this Problem problem) => - UnprocessableEntity(problem.AsProblemDetails()); + TypedResults.UnprocessableEntity(problem.AsProblemDetails()); /// - /// Returns a result with the specified + /// Returns a result with the specified /// [PublicAPI] public static BadRequest AsBadRequestResult(this Problem problem) => - BadRequest(problem.AsProblemDetails()); + TypedResults.BadRequest(problem.AsProblemDetails()); /// - /// Returns a result with the specified + /// Returns a result with the specified /// [PublicAPI] public static Conflict AsConflictResult(this Problem problem) => - Conflict(problem.AsProblemDetails()); + TypedResults.Conflict(problem.AsProblemDetails()); /// - /// Returns an result with the specified + /// Returns an result with the specified /// [PublicAPI] public static Ok AsOkResult(this Problem problem) => - Ok(problem.AsProblemDetails()); + TypedResults.Ok(problem.AsProblemDetails()); /// - /// Returns a result with the specified + /// Returns a result with the specified /// [PublicAPI] public static ProblemHttpResult AsProblemResult(this Problem problem) => - Problem(problem.AsProblemDetails()); + TypedResults.Problem(problem.AsProblemDetails()); } \ No newline at end of file diff --git a/src/ES.FX/Problems/ProblemException.cs b/src/ES.FX/Problems/ProblemException.cs index 8ac3595..e1ec77e 100644 --- a/src/ES.FX/Problems/ProblemException.cs +++ b/src/ES.FX/Problems/ProblemException.cs @@ -1,14 +1,14 @@ namespace ES.FX.Problems; /// -/// Exception that is thrown when a occurs. Contains the that occured. +/// Exception that is thrown when a occurs. Contains the that occured. /// -/// The +/// The public class ProblemException(Problem problem) : Exception($"A problem of type '{problem.Type}' occured. See '{nameof(Problem)}' for more details") { /// - /// The source + /// The source /// public Problem Problem { get; } = problem; } \ No newline at end of file diff --git a/src/ES.FX/Problems/ProblemExtensions.cs b/src/ES.FX/Problems/ProblemExtensions.cs index ae17407..2749a40 100644 --- a/src/ES.FX/Problems/ProblemExtensions.cs +++ b/src/ES.FX/Problems/ProblemExtensions.cs @@ -6,10 +6,10 @@ namespace ES.FX.Problems; public static class ProblemExtensions { /// - /// Throws a with the specified + /// Throws a with the specified /// - /// The + /// The /// - public static void Throw(this Problem problem) => + public static void Throw(this Problem problem) => throw new ProblemException(problem); } \ No newline at end of file