forked from stphnwlsh/CleanMinimalApi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring to Update - Endpoints, Validation and Swagger (stphnwlsh#21)
- Moving request validation to the Presentation project - Use IEndpointFilter to capture validation - Refactoring endpoints into mapping and methods - Update Swagger implementation - Adding more test coverage - General cleanup and refactoring
- Loading branch information
Showing
80 changed files
with
2,072 additions
and
1,041 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/Application/Authors/Queries/GetAuthorById/GetAuthorByIdValidator.cs
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/Application/Movies/Queries/GetMovieById/GetMovieByIdValidator.cs
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
src/Application/Reviews/Commands/DeleteReview/DeleteReviewValidator.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
src/Application/Reviews/Queries/GetReviewById/GetReviewByIdValidator.cs
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
namespace CleanMinimalApi.Presentation.Endpoints; | ||
|
||
using CleanMinimalApi.Application.Common.Exceptions; | ||
using CleanMinimalApi.Presentation.Filters; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Entities = Application.Authors.Entities; | ||
using Queries = Application.Authors.Queries; | ||
|
||
public static class AuthorsEndpoints | ||
{ | ||
public static WebApplication MapAuthorEndpoints(this WebApplication app) | ||
{ | ||
var root = app.MapGroup("/api/authors") | ||
.WithTags("authors") | ||
.WithOpenApi(); | ||
|
||
_ = root.MapGet("/", GetAuthors) | ||
.Produces<List<Entities.Author>>() | ||
.ProducesProblem(StatusCodes.Status500InternalServerError) | ||
.WithSummary("Lookup all Authors") | ||
.WithDescription("\n GET /Authors"); | ||
|
||
_ = root.MapGet("/{id}", GetAuthorById) | ||
.AddEndpointFilter<ValidationFilter<Guid>>() | ||
.Produces<Entities.Author>() | ||
.ProducesValidationProblem() | ||
.ProducesProblem(StatusCodes.Status404NotFound) | ||
.ProducesProblem(StatusCodes.Status500InternalServerError) | ||
.WithSummary("Lookup an Author by their Id") | ||
.WithDescription("\n GET /Authors/00000000-0000-0000-0000-000000000000"); | ||
|
||
return app; | ||
} | ||
|
||
public static async Task<IResult> GetAuthors(IMediator mediator) | ||
{ | ||
try | ||
{ | ||
return Results.Ok(await mediator.Send(new Queries.GetAuthors.GetAuthorsQuery())); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Results.Problem(ex.StackTrace, ex.Message, StatusCodes.Status500InternalServerError); | ||
} | ||
} | ||
|
||
public static async Task<IResult> GetAuthorById(Guid id, IMediator mediator) | ||
{ | ||
try | ||
{ | ||
return Results.Ok(await mediator.Send(new Queries.GetAuthorById.GetAuthorByIdQuery | ||
{ | ||
Id = id | ||
})); | ||
} | ||
catch (NotFoundException ex) | ||
{ | ||
return Results.NotFound(ex.Message); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Results.Problem(ex.StackTrace, ex.Message, StatusCodes.Status500InternalServerError); | ||
} | ||
} | ||
} |
Oops, something went wrong.