Refactoring Catalog.API controllers and EF config
This commit is contained in:
parent
02e4a43e3f
commit
ba11c78ef9
@ -24,10 +24,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
((DbContext)context).ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
}
|
||||
|
||||
// GET api/v1/[controller]/items/[?pageSize=3&pageIndex=10]
|
||||
// GET api/v1/[controller]/items[?pageSize=3&pageIndex=10]
|
||||
[HttpGet]
|
||||
[Route("[action]")]
|
||||
public async Task<IActionResult> Items(int pageSize = 10, int pageIndex = 0)
|
||||
public async Task<IActionResult> Items([FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
{
|
||||
var totalItems = await _context.CatalogItems
|
||||
.LongCountAsync();
|
||||
@ -46,10 +46,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
return Ok(model);
|
||||
}
|
||||
|
||||
// GET api/v1/[controller]/items/withname/samplename
|
||||
// GET api/v1/[controller]/items/withname/samplename[?pageSize=3&pageIndex=10]
|
||||
[HttpGet]
|
||||
[Route("[action]/withname/{name:minlength(1)}")]
|
||||
public async Task<IActionResult> Items(string name, int pageSize = 10, int pageIndex = 0)
|
||||
public async Task<IActionResult> Items(string name, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
{
|
||||
|
||||
var totalItems = await _context.CatalogItems
|
||||
@ -70,10 +70,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
|
||||
return Ok(model);
|
||||
}
|
||||
|
||||
// GET api/v1/[controller]/items/type/1/brand/null
|
||||
// GET api/v1/[controller]/items/type/1/brand/null[?pageSize=3&pageIndex=10]
|
||||
[HttpGet]
|
||||
[Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId}")]
|
||||
public async Task<IActionResult> Items(int? catalogTypeId, int? catalogBrandId, int pageSize = 10, int pageIndex = 0)
|
||||
public async Task<IActionResult> Items(int? catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0)
|
||||
{
|
||||
var root = (IQueryable<CatalogItem>)_context.CatalogItems;
|
||||
|
||||
|
@ -42,11 +42,10 @@
|
||||
services.AddDbContext<CatalogContext>(c =>
|
||||
{
|
||||
c.UseSqlServer(Configuration["ConnectionString"]);
|
||||
c.ConfigureWarnings(wb =>
|
||||
{
|
||||
//By default, in this application, we don't want to have client evaluations
|
||||
wb.Log(RelationalEventId.QueryClientEvaluationWarning);
|
||||
});
|
||||
// Changing default behavior when client evaluation occurs to throw.
|
||||
// Default in EF Core would be to log a warning when client evaluation is performed.
|
||||
c.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));
|
||||
//Check Client vs. Server evaluation: https://docs.microsoft.com/en-us/ef/core/querying/client-eval
|
||||
});
|
||||
|
||||
services.Configure<Settings>(Configuration);
|
||||
|
Loading…
x
Reference in New Issue
Block a user