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