|
|
@ -64,23 +64,26 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers |
|
|
|
{ |
|
|
|
var numIds = ids.Split(',') |
|
|
|
.Select(id => (Ok: int.TryParse(id, out int x), Value: x)); |
|
|
|
|
|
|
|
if (!numIds.All(nid => nid.Ok)) |
|
|
|
{ |
|
|
|
return BadRequest("ids value invalid. Must be comma-separated list of numbers"); |
|
|
|
} |
|
|
|
|
|
|
|
var idsToSelect = numIds.Select(id => id.Value); |
|
|
|
var idsToSelect = numIds |
|
|
|
.Select(id => id.Value); |
|
|
|
|
|
|
|
var items = _catalogContext.CatalogItems.Where(ci => idsToSelect.Contains(ci.Id)).ToList(); |
|
|
|
|
|
|
|
items = ChangeUriPlaceholder(items); |
|
|
|
return Ok(items); |
|
|
|
|
|
|
|
return Ok(items); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
[Route("items/{id:int}")] |
|
|
|
[ProducesResponseType((int)HttpStatusCode.NotFound)] |
|
|
|
[ProducesResponseType(typeof(CatalogItem),(int)HttpStatusCode.OK)] |
|
|
|
[ProducesResponseType(typeof(CatalogItem), (int)HttpStatusCode.OK)] |
|
|
|
public async Task<IActionResult> GetItemById(int id) |
|
|
|
{ |
|
|
|
if (id <= 0) |
|
|
@ -127,19 +130,44 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers |
|
|
|
return Ok(model); |
|
|
|
} |
|
|
|
|
|
|
|
// GET api/v1/[controller]/items/type/1/brand/null[?pageSize=3&pageIndex=10]
|
|
|
|
// GET api/v1/[controller]/items/type/1/brand[?pageSize=3&pageIndex=10]
|
|
|
|
[HttpGet] |
|
|
|
[Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId}")]
|
|
|
|
[Route("[action]/type/{catalogTypeId}/brand/{catalogBrandId:int?}")]
|
|
|
|
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] |
|
|
|
public async Task<IActionResult> Items(int? catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0) |
|
|
|
public async Task<IActionResult> Items(int catalogTypeId, int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0) |
|
|
|
{ |
|
|
|
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems; |
|
|
|
|
|
|
|
if (catalogTypeId.HasValue) |
|
|
|
root = root.Where(ci => ci.CatalogTypeId == catalogTypeId); |
|
|
|
|
|
|
|
if (catalogBrandId.HasValue) |
|
|
|
{ |
|
|
|
root = root.Where(ci => ci.CatalogTypeId == catalogTypeId); |
|
|
|
root = root.Where(ci => ci.CatalogBrandId == catalogBrandId); |
|
|
|
} |
|
|
|
|
|
|
|
var totalItems = await root |
|
|
|
.LongCountAsync(); |
|
|
|
|
|
|
|
var itemsOnPage = await root |
|
|
|
.Skip(pageSize * pageIndex) |
|
|
|
.Take(pageSize) |
|
|
|
.ToListAsync(); |
|
|
|
|
|
|
|
itemsOnPage = ChangeUriPlaceholder(itemsOnPage); |
|
|
|
|
|
|
|
var model = new PaginatedItemsViewModel<CatalogItem>( |
|
|
|
pageIndex, pageSize, totalItems, itemsOnPage); |
|
|
|
|
|
|
|
return Ok(model); |
|
|
|
} |
|
|
|
// GET api/v1/[controller]/items/type/all/brand[?pageSize=3&pageIndex=10]
|
|
|
|
[HttpGet] |
|
|
|
[Route("[action]/type/all/brand/{catalogBrandId:int?}")]
|
|
|
|
[ProducesResponseType(typeof(PaginatedItemsViewModel<CatalogItem>), (int)HttpStatusCode.OK)] |
|
|
|
public async Task<IActionResult> Items(int? catalogBrandId, [FromQuery]int pageSize = 10, [FromQuery]int pageIndex = 0) |
|
|
|
{ |
|
|
|
var root = (IQueryable<CatalogItem>)_catalogContext.CatalogItems; |
|
|
|
|
|
|
|
if (catalogBrandId.HasValue) |
|
|
|
{ |
|
|
|
root = root.Where(ci => ci.CatalogBrandId == catalogBrandId); |
|
|
|