Browse Source

Refactoring Catalog.API controllers and EF config

pull/78/head
Cesar De la Torre 8 years ago
parent
commit
ba11c78ef9
2 changed files with 10 additions and 11 deletions
  1. +6
    -6
      src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs
  2. +4
    -5
      src/Services/Catalog/Catalog.API/Startup.cs

+ 6
- 6
src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs View File

@ -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;


+ 4
- 5
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -42,11 +42,10 @@
services.AddDbContext<CatalogContext>(c => services.AddDbContext<CatalogContext>(c =>
{ {
c.UseSqlServer(Configuration["ConnectionString"]); 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); services.Configure<Settings>(Configuration);


Loading…
Cancel
Save