Skip to content

Commit c509101

Browse files
author
Carlos Cañizares Estévez
committed
Integration with Catalog api, filter and pagination.
1 parent 45bc1f8 commit c509101

21 files changed

Lines changed: 111 additions & 78 deletions

src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public static async Task SeedAsync(IApplicationBuilder applicationBuilder)
1515

1616
using (context)
1717
{
18-
context.Database.EnsureDeleted();
19-
2018
context.Database.EnsureCreated();
2119

2220
if (!context.CatalogBrands.Any())

src/Services/Catalog/Catalog.API/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public Startup(IHostingEnvironment env)
2121
{
2222
var builder = new ConfigurationBuilder()
2323
.SetBasePath(env.ContentRootPath)
24-
.AddJsonFile($"settings.{env.EnvironmentName}.json",optional:false)
24+
.AddJsonFile($"settings.json",optional:false)
2525
.AddEnvironmentVariables();
2626

2727

src/Services/Catalog/Catalog.API/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"wwwroot",
4444
"Views",
4545
"Areas/**/Views",
46-
"settings.Production.json",
46+
"settings.json",
4747
"web.config",
4848
"project.json",
4949
"Dockerfile"
File renamed without changes.

src/Services/Catalog/Catalog.API/settings.production.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/Web/WebMVC/Controllers/CartController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public async Task<IActionResult> AddToCart(string productId)
5858
Id = Guid.NewGuid().ToString(),
5959
Quantity = 1,
6060
ProductName = productDetails.Name,
61-
PictureUrl = productDetails.PictureUrl,
61+
PictureUrl = productDetails.PictureUri,
6262
UnitPrice = productDetails.Price,
6363
ProductId = productId
6464
};

src/Web/WebMVC/Controllers/CatalogController.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@ public CatalogController(ICatalogService catalogSvc)
2424

2525
public async Task<IActionResult> Index(int? BrandFilterApplied, int? TypesFilterApplied, int? page)
2626
{
27+
var itemsPage = 10;
28+
var catalog = await _catalogSvc.GetCatalogItems(page ?? 0, itemsPage, BrandFilterApplied, TypesFilterApplied);
2729
var vm = new IndexViewModel()
2830
{
29-
CatalogItems = await _catalogSvc.GetCatalogItems(6 * (page ?? 0), 6),
30-
Brands = _catalogSvc.GetBrands(),
31-
Types = _catalogSvc.GetTypes(),
31+
CatalogItems = catalog.Data,
32+
Brands = await _catalogSvc.GetBrands(),
33+
Types = await _catalogSvc.GetTypes(),
3234
BrandFilterApplied = BrandFilterApplied ?? 0,
3335
TypesFilterApplied = TypesFilterApplied ?? 0,
3436
PaginationInfo = new PaginationInfo()
3537
{
3638
ActualPage = page ?? 0,
37-
ItemsPerPage = 6,
39+
ItemsPerPage = (_catalogSvc.TotalItems < itemsPage) ? _catalogSvc.TotalItems : itemsPage,
3840
TotalItems = _catalogSvc.TotalItems,
39-
TotalPages = int.Parse(Math.Round(((decimal)_catalogSvc.TotalItems / 6), MidpointRounding.AwayFromZero).ToString())
41+
TotalPages = int.Parse(Math.Ceiling(((decimal)_catalogSvc.TotalItems / itemsPage)).ToString())
4042
}
4143
};
4244

src/Web/WebMVC/Models/Catalog.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Microsoft.eShopOnContainers.WebMVC.Models
7+
{
8+
public class Catalog
9+
{
10+
public int PageIndex { get; set; }
11+
public int PageSize { get; set; }
12+
public int Count { get; set; }
13+
public List<CatalogItem> Data { get; set; }
14+
}
15+
}

src/Web/WebMVC/Models/CatalogItem.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public class CatalogItem
88
public string Name { get; set; }
99
public string Description { get; set; }
1010
public decimal Price { get; set; }
11-
public string PictureUrl { get; set; }
11+
public string PictureUri { get; set; }
12+
public int CatalogBrandId { get; set; }
13+
public string CatalogBrand { get; set; }
14+
public int CatalogTypeId { get; set; }
15+
public string CatalogType { get; set; }
16+
1217
}
1318
}

src/Web/WebMVC/Services/CatalogService.cs

Lines changed: 69 additions & 42 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)