Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Used Minimal APIs builders instead of custom one in Warehouse CQRS ex…
…ample
- Loading branch information
1 parent
bb6c3fe
commit 8038755
Showing
7 changed files
with
31 additions
and
138 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
100 changes: 0 additions & 100 deletions
100
Sample/Warehouse/Warehouse/Core/Extensions/HttpExtensions.cs
This file was deleted.
Oops, something went wrong.
21 changes: 6 additions & 15 deletions
21
Sample/Warehouse/Warehouse/Products/GettingProductDetails/Route.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 |
---|---|---|
@@ -1,33 +1,24 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Routing; | ||
using Warehouse.Core.Extensions; | ||
using Warehouse.Core.Queries; | ||
using static Microsoft.AspNetCore.Http.Results; | ||
|
||
namespace Warehouse.Products.GettingProductDetails; | ||
|
||
public static class Route | ||
{ | ||
internal static IEndpointRouteBuilder UseGetProductDetailsEndpoint(this IEndpointRouteBuilder endpoints) | ||
{ | ||
endpoints.MapGet("/api/products/{id}", async context => | ||
endpoints.MapGet("/api/products/{id:guid}", async (HttpContext context, Guid id) => | ||
{ | ||
// var dbContext = WarehouseDBContextFactory.Create(); | ||
// var handler = new HandleGetProductDetails(dbContext.Set<Product>().AsQueryable()); | ||
var productId = context.FromRoute<Guid>("id"); | ||
var query = GetProductDetails.Create(productId); | ||
var query = GetProductDetails.Create(id); | ||
var result = await context | ||
.SendQuery<GetProductDetails, ProductDetails?>(query); | ||
if (result == null) | ||
{ | ||
context.NotFound(); | ||
return; | ||
} | ||
await context.OK(result); | ||
return result != null ? Ok(result) : NotFound(); | ||
}); | ||
return endpoints; | ||
} | ||
} | ||
} |
17 changes: 6 additions & 11 deletions
17
Sample/Warehouse/Warehouse/Products/GettingProducts/Route.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 |
---|---|---|
@@ -1,30 +1,25 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Routing; | ||
using Warehouse.Core.Extensions; | ||
using Warehouse.Core.Queries; | ||
using static Microsoft.AspNetCore.Http.Results; | ||
|
||
namespace Warehouse.Products.GettingProducts; | ||
|
||
public static class Route | ||
{ | ||
internal static IEndpointRouteBuilder UseGetProductsEndpoint(this IEndpointRouteBuilder endpoints) | ||
{ | ||
endpoints.MapGet("/api/products", async context => | ||
endpoints.MapGet("/api/products", async (HttpContext context, [FromQuery]string? filter, [FromQuery]int? page, [FromQuery]int? pageSize) => | ||
{ | ||
// var dbContext = WarehouseDBContextFactory.Create(); | ||
// var handler = new HandleGetProducts(dbContext.Set<Product>().AsQueryable()); | ||
var filter = context.FromQuery("filter"); | ||
var page = context.FromQuery<int>("page"); | ||
var pageSize = context.FromQuery<int>("pageSize"); | ||
var query = GetProducts.Create(filter, page, pageSize); | ||
var result = await context | ||
.SendQuery<GetProducts, IReadOnlyList<ProductListItem>>(query); | ||
await context.OK(result); | ||
return Ok(result); | ||
}); | ||
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