Skip to content

Commit 0716bff

Browse files
committed
Removed hardcoded addresses for persisted picture uris
1 parent 10ea5f7 commit 0716bff

7 files changed

Lines changed: 41 additions & 62 deletions

File tree

src/Web/WebMonolithic/docker-compose.override.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
environment:
66
- ASPNETCORE_ENVIRONMENT=Development
77
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word
8+
- CatalogBaseUrl=http://localhost:5106
89
ports:
910
- "5106:5106"
1011

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace eShopWeb
2+
{
3+
public class CatalogSettings
4+
{
5+
public string CatalogBaseUrl { get; set; }
6+
}
7+
}

src/Web/WebMonolithic/eShopWeb/Infrastructure/CatalogContextSeed.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,18 @@ static IEnumerable<CatalogItem> GetPreconfiguredItems()
8585
{
8686
return new List<CatalogItem>()
8787
{
88-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://localhost:5106/catalog/pic/1" },
89-
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://localhost:5106/catalog/pic/2" },
90-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/3" },
91-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/4" },
92-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/5" },
93-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/6" },
94-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/7" },
95-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/8" },
96-
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/9" },
97-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/10" },
98-
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://localhost:5106/catalog/pic/11" },
99-
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://localhost:5106/catalog/pic/12" }
88+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Bot Black Sweatshirt", Name = ".NET Bot Black Sweatshirt", Price = 19.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/1" },
89+
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=2, Description = ".NET Black & White Mug", Name = ".NET Black & White Mug", Price= 8.50M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/2" },
90+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White T-Shirt", Name = "Prism White T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/3" },
91+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/4" },
92+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/5" },
93+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/6" },
94+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Roslyn Red T-Shirt", Name = "Roslyn Red T-Shirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/7" },
95+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/8" },
96+
new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup<T> White Mug", Name = "Cup<T> White Mug", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/9" },
97+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/10" },
98+
new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/11" },
99+
new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://catalogbaseurltobereplaced/catalog/pic/12" }
100100
};
101101
}
102102
}

src/Web/WebMonolithic/eShopWeb/ScaffoldingReadMe.txt

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

src/Web/WebMonolithic/eShopWeb/Services/CatalogService.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
using Microsoft.AspNetCore.Mvc.Rendering;
77
using eShopWeb.Infrastructure;
88
using Microsoft.EntityFrameworkCore;
9+
using Microsoft.Extensions.Options;
10+
using Microsoft.Extensions.Configuration;
911

1012
namespace eShopWeb.Services
1113
{
1214
public class CatalogService : ICatalogService
1315
{
1416
private readonly CatalogContext _context;
15-
public CatalogService(CatalogContext context)
17+
private readonly IOptionsSnapshot<CatalogSettings> _settings;
18+
19+
public CatalogService(CatalogContext context, IOptionsSnapshot<CatalogSettings> settings)
1620
{
1721
_context = context;
22+
_settings = settings;
1823
}
1924

2025
public async Task<Catalog> GetCatalogItems(int pageIndex, int itemsPage, int? brandId, int? typeId)
@@ -39,6 +44,8 @@ public async Task<Catalog> GetCatalogItems(int pageIndex, int itemsPage, int? br
3944
.Take(itemsPage)
4045
.ToListAsync();
4146

47+
itemsOnPage = ComposePicUri(itemsOnPage);
48+
4249
return new Catalog() { Data = itemsOnPage, PageIndex = pageIndex, Count = (int)totalItems };
4350
}
4451

@@ -67,5 +74,16 @@ public async Task<IEnumerable<SelectListItem>> GetTypes()
6774

6875
return items;
6976
}
77+
78+
private List<CatalogItem> ComposePicUri(List<CatalogItem> items)
79+
{
80+
var baseUri = _settings.Value.CatalogBaseUrl;
81+
items.ForEach(x =>
82+
{
83+
x.PictureUri = x.PictureUri.Replace("http://catalogbaseurltobereplaced", baseUri);
84+
});
85+
86+
return items;
87+
}
7088
}
7189
}

src/Web/WebMonolithic/eShopWeb/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public void ConfigureServices(IServiceCollection services)
4646
});
4747

4848
services.AddTransient<ICatalogService, CatalogService>();
49+
services.Configure<CatalogSettings>(Configuration);
4950
services.AddMvc();
5051
}
5152

src/Web/WebMonolithic/eShopWeb/appsettings.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+
"CatalogBaseUrl": "http://localhost:5106",
34
"Logging": {
45
"IncludeScopes": false,
56
"LogLevel": {

0 commit comments

Comments
 (0)