Skip to content

Commit 93bbd65

Browse files
author
PLAINCONCEPTS\ccanizares
committed
Catalog Seed: Dynamic host url for image pics
1 parent bbb6303 commit 93bbd65

6 files changed

Lines changed: 50 additions & 28 deletions

File tree

docker-compose.override.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ services:
1313
environment:
1414
- CatalogUrl=http://catalog.api:5101
1515
- OrderingUrl=http://ordering.api:5102
16-
#- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105.
17-
- IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
16+
- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105.
17+
#- IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
1818
#- IdentityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker.
1919
- BasketUrl=http://basket.api:5103
2020
ports:
@@ -24,44 +24,46 @@ services:
2424
environment:
2525
- CatalogUrl=http://catalog.api:5101
2626
- OrderingUrl=http://ordering.api:5102
27-
#- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105.
27+
- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105.
2828
#- IdentityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker.
29-
- IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
29+
#- IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
3030
- BasketUrl=http://basket.api:5103
3131
ports:
3232
- "5104:5104"
3333

3434
basket.api:
3535
environment:
3636
- ConnectionString=basket.data
37-
#- identityUrl=http://13.88.8.119:5105 #Remote
37+
- identityUrl=http://13.88.8.119:5105 #Remote
3838
#- identityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker.
39-
- identityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
39+
#- identityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
4040
ports:
4141
- "5103:5103"
4242

4343
catalog.api:
4444
environment:
4545
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word
46+
#- ExternalCatalogBaseUrl=http://10.0.75.1:5101 #Local
47+
- ExternalCatalogBaseUrl=http://13.88.8.119:5101 #Remote
4648
ports:
4749
- "5101:5101"
4850

4951
ordering.api:
5052
environment:
5153
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
52-
#- identityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105.
54+
- identityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105.
5355
#- identityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker.
54-
- identityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
56+
#- identityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105.
5557
ports:
5658
- "5102:5102"
5759

5860
identity.service:
5961
environment:
6062
- SpaClient=http://localhost:5104
6163
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word
62-
#- MvcClient=http://13.88.8.119:5100 #Remote: VM Needs to have public access at 5105.
64+
- MvcClient=http://13.88.8.119:5100 #Remote: VM Needs to have public access at 5105.
6365
#- MvcClient=http://localhost:5100 #Local: You need a entry in windows host file to run identity in local docker.
64-
- MvcClient=http://10.0.75.1:5100 #Local: You need to open windows firewall at range 5100-5105.
66+
#- MvcClient=http://10.0.75.1:5100 #Local: You need to open windows firewall at range 5100-5105.
6567
ports:
6668
- "5105:5105"
6769

src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
33
{
4+
using Extensions.Options;
45
using Microsoft.AspNetCore.Mvc;
56
using Microsoft.EntityFrameworkCore;
67
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
@@ -15,10 +16,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
1516
public class CatalogController : ControllerBase
1617
{
1718
private readonly CatalogContext _context;
19+
private readonly IOptions<Settings> _settings;
1820

19-
public CatalogController(CatalogContext context)
21+
public CatalogController(CatalogContext context, IOptions<Settings> settings)
2022
{
2123
_context = context;
24+
_settings = settings;
2225
}
2326

2427
// GET api/v1/[controller]/items/[?pageSize=3&pageIndex=10]
@@ -35,7 +38,7 @@ public async Task<IActionResult> Items(int pageSize = 10, int pageIndex = 0)
3538
.Take(pageSize)
3639
.ToListAsync();
3740

38-
//itemsOnPage = ComposePicUri(itemsOnPage);
41+
itemsOnPage = ComposePicUri(itemsOnPage);
3942

4043
var model = new PaginatedItemsViewModel<CatalogItem>(
4144
pageIndex, pageSize, totalItems, itemsOnPage);
@@ -59,7 +62,7 @@ public async Task<IActionResult> Items(string name, int pageSize = 10, int pageI
5962
.Take(pageSize)
6063
.ToListAsync();
6164

62-
//itemsOnPage = ComposePicUri(itemsOnPage);
65+
itemsOnPage = ComposePicUri(itemsOnPage);
6366

6467
var model = new PaginatedItemsViewModel<CatalogItem>(
6568
pageIndex, pageSize, totalItems, itemsOnPage);
@@ -92,7 +95,7 @@ public async Task<IActionResult> Items(int? catalogTypeId, int? catalogBrandId,
9295
.Take(pageSize)
9396
.ToListAsync();
9497

95-
//itemsOnPage = ComposePicUri(itemsOnPage);
98+
itemsOnPage = ComposePicUri(itemsOnPage);
9699

97100
var model = new PaginatedItemsViewModel<CatalogItem>(
98101
pageIndex, pageSize, totalItems, itemsOnPage);
@@ -123,9 +126,10 @@ public async Task<IActionResult> CatalogBrands()
123126
}
124127

125128
private List<CatalogItem> ComposePicUri(List<CatalogItem> items) {
129+
var baseUri = _settings.Value.ExternalCatalogBaseUrl;
126130
items.ForEach(x =>
127131
{
128-
x.PictureUri = x.PictureUri.Replace("localhost", Request.Host.Host);
132+
x.PictureUri = x.PictureUri.Replace("http://externalcatalogbaseurltobereplaced", baseUri);
129133
});
130134

131135
return items;

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static IEnumerable<CatalogBrand> GetPreconfiguredCatalogBrands()
6464
new CatalogBrand() { Brand = "Azure"},
6565
new CatalogBrand() { Brand = ".NET" },
6666
new CatalogBrand() { Brand = "Visual Studio" },
67-
new CatalogBrand() { Brand = "SQL Server" }
67+
new CatalogBrand() { Brand = "SQL Server" },
68+
new CatalogBrand() { Brand = "Other" }
6869
};
6970
}
7071

@@ -83,18 +84,18 @@ static IEnumerable<CatalogItem> GetPreconfiguredItems()
8384
{
8485
return new List<CatalogItem>()
8586
{
86-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://localhost:5101/api/v1/pic/1" },
87-
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://localhost:5101/api/v1/pic/2" },
88-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/3" },
89-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/4" },
90-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://localhost:5101/api/v1/pic/5" },
91-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/6" },
92-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/7" },
93-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET Purple Sweatshirt", Name = ".NET Purple Sweatshirt", Price = 8.5M, PictureUri = "http://localhost:5101/api/v1/pic/8" },
94-
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=1, Description = ".NET T White Mug", Name = ".NET T White Mug", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/9" },
95-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/10" },
96-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET T Sheet", Name = ".NET T Sheet", Price = 8.5M, PictureUri = "http://localhost:5101/api/v1/pic/11" },
97-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/12" }
87+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/1" },
88+
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" },
89+
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" },
90+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4" },
91+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5" },
92+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6" },
93+
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" },
94+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8" },
95+
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" },
96+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10" },
97+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11" },
98+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12" }
9899
};
99100
}
100101
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public void ConfigureServices(IServiceCollection services)
5050
});
5151
});
5252

53+
services.Configure<Settings>(Configuration);
54+
5355
// Add framework services.
5456
services.AddSwaggerGen();
5557
services.ConfigureSwaggerGen(options =>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Microsoft.eShopOnContainers.Services.Catalog.API
7+
{
8+
public class Settings
9+
{
10+
public string ExternalCatalogBaseUrl {get;set;}
11+
}
12+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word",
3+
"ExternalCatalogBaseUrl": "http://localhost:5101",
34
"Logging": {
45
"IncludeScopes": false,
56
"LogLevel": {

0 commit comments

Comments
 (0)