Skip to content

Commit

Permalink
refactor(Problems): update method calls and improve code readability
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
winromulus committed Oct 14, 2024
1 parent e58d02a commit 2b6bff0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions src/ES.FX.Microsoft.AspNetCore/Problems/ProblemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,9 +32,9 @@ public static class ProblemExtensions
};

/// <summary>
/// Formats a <see cref="Problem"/> as <see cref="ProblemDetails"/>
/// Formats a <see cref="Problem" /> as <see cref="ProblemDetails" />
/// </summary>
/// <param name="problem">The source <see cref="Problem"/></param>
/// <param name="problem">The source <see cref="Problem" /></param>
[PublicAPI]
public static ProblemDetails AsProblemDetails(this Problem problem)
{
Expand Down Expand Up @@ -72,37 +72,37 @@ public static ProblemDetails AsProblemDetails(this Problem problem)
}

/// <summary>
/// Returns an <see cref="UnprocessableEntity{ProblemDetails}"/> result with the specified <see cref="Problem"/>
/// Returns an <see cref="UnprocessableEntity{ProblemDetails}" /> result with the specified <see cref="Problem" />
/// </summary>
[PublicAPI]
public static UnprocessableEntity<ProblemDetails> AsUnprocessableEntityResult(this Problem problem) =>
UnprocessableEntity(problem.AsProblemDetails());
TypedResults.UnprocessableEntity(problem.AsProblemDetails());

/// <summary>
/// Returns a <see cref="BadRequest{ProblemDetails}"/> result with the specified <see cref="Problem"/>
/// Returns a <see cref="BadRequest{ProblemDetails}" /> result with the specified <see cref="Problem" />
/// </summary>
[PublicAPI]
public static BadRequest<ProblemDetails> AsBadRequestResult(this Problem problem) =>
BadRequest(problem.AsProblemDetails());
TypedResults.BadRequest(problem.AsProblemDetails());

/// <summary>
/// Returns a <see cref="Conflict{ProblemDetails}"/> result with the specified <see cref="Problem"/>
/// Returns a <see cref="Conflict{ProblemDetails}" /> result with the specified <see cref="Problem" />
/// </summary>
[PublicAPI]
public static Conflict<ProblemDetails> AsConflictResult(this Problem problem) =>
Conflict(problem.AsProblemDetails());
TypedResults.Conflict(problem.AsProblemDetails());

/// <summary>
/// Returns an <see cref="Ok{ProblemDetails}"/> result with the specified <see cref="Problem"/>
/// Returns an <see cref="Ok{ProblemDetails}" /> result with the specified <see cref="Problem" />
/// </summary>
[PublicAPI]
public static Ok<ProblemDetails> AsOkResult(this Problem problem) =>
Ok(problem.AsProblemDetails());
TypedResults.Ok(problem.AsProblemDetails());

/// <summary>
/// Returns a <see cref="ProblemHttpResult"/> result with the specified <see cref="Problem"/>
/// Returns a <see cref="ProblemHttpResult" /> result with the specified <see cref="Problem" />
/// </summary>
[PublicAPI]
public static ProblemHttpResult AsProblemResult(this Problem problem) =>
Problem(problem.AsProblemDetails());
TypedResults.Problem(problem.AsProblemDetails());
}
6 changes: 3 additions & 3 deletions src/ES.FX/Problems/ProblemException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace ES.FX.Problems;

/// <summary>
/// Exception that is thrown when a <see cref="Problem"/> occurs. Contains the <see cref="Problem"/> that occured.
/// Exception that is thrown when a <see cref="Problem" /> occurs. Contains the <see cref="Problem" /> that occured.
/// </summary>
/// <param name="problem">The <see cref="Problem"/></param>
/// <param name="problem">The <see cref="Problem" /></param>
public class ProblemException(Problem problem)
: Exception($"A problem of type '{problem.Type}' occured. See '{nameof(Problem)}' for more details")
{
/// <summary>
/// The source <see cref="Problem"/>
/// The source <see cref="Problem" />
/// </summary>
public Problem Problem { get; } = problem;
}
6 changes: 3 additions & 3 deletions src/ES.FX/Problems/ProblemExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace ES.FX.Problems;
public static class ProblemExtensions
{
/// <summary>
/// Throws a <see cref="ProblemException"/> with the specified <see cref="Problem"/>
/// Throws a <see cref="ProblemException" /> with the specified <see cref="Problem" />
/// </summary>
/// <param name="problem">The <see cref="Problem"/></param>
/// <param name="problem">The <see cref="Problem" /></param>
/// <exception cref="ProblemException"></exception>
public static void Throw(this Problem problem) =>
public static void Throw(this Problem problem) =>
throw new ProblemException(problem);
}

0 comments on commit 2b6bff0

Please sign in to comment.