Skip to content

Commit 5f28f8f

Browse files
committed
Updated number of products in catalog stock
Orders list ordered Refresh orders list periodically Fix bug SPA basket not dropped after creating order
1 parent a56a795 commit 5f28f8f

6 files changed

Lines changed: 48 additions & 14 deletions

File tree

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ static IEnumerable<CatalogItem> GetPreconfiguredItems()
7070
{
7171
return new List<CatalogItem>()
7272
{
73-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Hoodie", Name = ".NET Bot Black Hoodie", Price = 19.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/1", AvailableStock = 1},
74-
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/2", AvailableStock = 1 },
75-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/3", AvailableStock = 1 },
76-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation T-shirt", Name = ".NET Foundation T-shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4", AvailableStock = 1 },
77-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5", AvailableStock = 1 },
78-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Hoodie", Name = ".NET Blue Hoodie", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6", AvailableStock = 1 },
79-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/7", AvailableStock = 1 },
80-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Hoodie", Name = "Kudu Purple Hoodie", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8", AvailableStock = 1 },
81-
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/9", AvailableStock = 1 },
82-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10", AvailableStock = 1 },
83-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11", AvailableStock = 1 },
84-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12", AvailableStock = 1 }
73+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Hoodie", Name = ".NET Bot Black Hoodie", Price = 19.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/1", AvailableStock = 100},
74+
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/2", AvailableStock = 100 },
75+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/3", AvailableStock = 100 },
76+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation T-shirt", Name = ".NET Foundation T-shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4", AvailableStock = 100 },
77+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5", AvailableStock = 100 },
78+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Hoodie", Name = ".NET Blue Hoodie", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6", AvailableStock = 100 },
79+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/7", AvailableStock = 100 },
80+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Hoodie", Name = "Kudu Purple Hoodie", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8", AvailableStock = 100 },
81+
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/9", AvailableStock = 100 },
82+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10", AvailableStock = 100 },
83+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11", AvailableStock = 100 },
84+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12", AvailableStock = 100 }
8585
};
8686
}
8787
}

src/Services/Ordering/Ordering.API/Application/Queries/OrderQueries.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ public async Task<IEnumerable<dynamic>> GetOrdersAsync()
5353
return await connection.QueryAsync<dynamic>(@"SELECT o.[Id] as ordernumber,o.[OrderDate] as [date],os.[Name] as [status],SUM(oi.units*oi.unitprice) as total
5454
FROM [ordering].[Orders] o
5555
LEFT JOIN[ordering].[orderitems] oi ON o.Id = oi.orderid
56-
LEFT JOIN[ordering].[orderstatus] os on o.OrderStatusId = os.Id
57-
GROUP BY o.[Id], o.[OrderDate], os.[Name]");
56+
LEFT JOIN[ordering].[orderstatus] os on o.OrderStatusId = os.Id
57+
GROUP BY o.[Id], o.[OrderDate], os.[Name]
58+
ORDER BY o.[Id]");
5859
}
5960
}
6061

src/Web/WebMVC/Views/Order/Index.cshtml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@
4040
}
4141
</div>
4242
</div>
43+
<script>
44+
setTimeout(function () {
45+
window.location.reload(true);
46+
}, 5000);
47+
</script>

src/Web/WebSPA/Client/modules/basket/basket.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ export class BasketService {
5151
}
5252
}
5353
}
54+
55+
this.basketEvents.orderCreated$.subscribe(x => {
56+
this.dropBasket();
57+
});
5458
}
5559

5660
addItemToBasket(item): Observable<boolean> {
@@ -67,6 +71,7 @@ export class BasketService {
6771

6872
setBasketCheckout(basketCheckout): Observable<boolean> {
6973
return this.service.postWithId(this.basketUrl + '/checkout', basketCheckout).map((response: Response) => {
74+
this.basketEvents.orderCreated();
7075
return true;
7176
});
7277
}
@@ -100,6 +105,11 @@ export class BasketService {
100105
return basketCheckout;
101106
}
102107

108+
dropBasket() {
109+
this.basket.items = [];
110+
this.basketDropedSource.next();
111+
}
112+
103113
private loadData() {
104114
this.getBasket().subscribe(basket => {
105115
if (basket != null)

src/Web/WebSPA/Client/modules/orders/orders.component.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { ConfigurationService } from '../shared/services/configuration.service';
99
templateUrl: './orders.component.html'
1010
})
1111
export class OrdersComponent implements OnInit {
12+
private oldOrders: IOrder[];
13+
private interval = null;
14+
1215
orders: IOrder[];
1316

1417
constructor(private service: OrdersService, private configurationService: ConfigurationService) { }
@@ -21,12 +24,23 @@ export class OrdersComponent implements OnInit {
2124
this.getOrders();
2225
});
2326
}
27+
28+
// call orders until new order is retrieved
29+
this.interval = setTimeout(() => {
30+
this.service.getOrders().subscribe(orders => {
31+
this.orders = orders;
32+
if (this.orders.length != this.oldOrders.length) {
33+
clearInterval(this.interval);
34+
}
35+
});
36+
}, 1000);
2437
}
2538

2639

2740
getOrders() {
2841
this.service.getOrders().subscribe(orders => {
2942
this.orders = orders;
43+
this.oldOrders = this.orders;
3044
console.log('orders items retrieved: ' + orders.length);
3145
});
3246
}

src/Web/WebSPA/WebSPA.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@
9090
</None>
9191
</ItemGroup>
9292

93+
<ItemGroup>
94+
<Folder Include="wwwroot\assets\" />
95+
</ItemGroup>
96+
9397
</Project>

0 commit comments

Comments
 (0)