-
-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added example of MapCommand for extreme endpoints handling
- Loading branch information
1 parent
b9341c4
commit 69fef36
Showing
10 changed files
with
86 additions
and
65 deletions.
There are no files selected for viewing
4 changes: 1 addition & 3 deletions
4
...le/Warehouse/Warehouse.Api.Tests/Products/GettingProductDetails/GetProductDetailsTests.cs
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
36 changes: 36 additions & 0 deletions
36
Sample/Warehouse/Warehouse/Core/Extensions/EndpointsExtensions.cs
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,36 @@ | ||
using System; | ||
using System.Net; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Routing; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http; | ||
using Warehouse.Core.Commands; | ||
|
||
namespace Warehouse.Core.Extensions | ||
{ | ||
internal static class EndpointsExtensions | ||
{ | ||
internal static IEndpointRouteBuilder MapCommand<TRequest>( | ||
this IEndpointRouteBuilder endpoints, | ||
HttpMethod httpMethod, | ||
string url, | ||
HttpStatusCode statusCode = HttpStatusCode.OK) | ||
{ | ||
endpoints.MapMethods(url, new []{httpMethod.ToString()} , async context => | ||
{ | ||
var command = await context.FromBody<TRequest>(); | ||
var commandResult = await context.SendCommand(command); | ||
if (commandResult == CommandResult.None) | ||
{ | ||
context.Response.StatusCode = (int)statusCode; | ||
return; | ||
} | ||
await context.ReturnJSON(commandResult.Result, statusCode); | ||
}); | ||
|
||
return endpoints; | ||
} | ||
} | ||
} |
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
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
36 changes: 0 additions & 36 deletions
36
Sample/Warehouse/Warehouse/Products/RegisteringProduct/Route.cs
This file was deleted.
Oops, something went wrong.