From 93bbd6516bd555b43c5a654dafaf64ad8342ea8c Mon Sep 17 00:00:00 2001 From: "PLAINCONCEPTS\\ccanizares" Date: Mon, 9 Jan 2017 10:33:43 +0100 Subject: [PATCH] Catalog Seed: Dynamic host url for image pics --- docker-compose.override.yml | 22 ++++++++------- .../Controllers/CatalogController.cs | 14 ++++++---- .../Infrastructure/CatalogContextSeed.cs | 27 ++++++++++--------- src/Services/Catalog/Catalog.API/Startup.cs | 2 ++ src/Services/Catalog/Catalog.API/settings.cs | 12 +++++++++ .../Catalog/Catalog.API/settings.json | 1 + 6 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 src/Services/Catalog/Catalog.API/settings.cs diff --git a/docker-compose.override.yml b/docker-compose.override.yml index c6ea3459d..410bfd159 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -13,8 +13,8 @@ services: environment: - CatalogUrl=http://catalog.api:5101 - OrderingUrl=http://ordering.api:5102 - #- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. - - IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105. + - IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. + #- IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105. #- IdentityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker. - BasketUrl=http://basket.api:5103 ports: @@ -24,9 +24,9 @@ services: environment: - CatalogUrl=http://catalog.api:5101 - OrderingUrl=http://ordering.api:5102 - #- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. + - IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. #- IdentityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker. - - IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105. + #- IdentityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105. - BasketUrl=http://basket.api:5103 ports: - "5104:5104" @@ -34,24 +34,26 @@ services: basket.api: environment: - ConnectionString=basket.data - #- identityUrl=http://13.88.8.119:5105 #Remote + - identityUrl=http://13.88.8.119:5105 #Remote #- identityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker. - - identityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105. + #- identityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105. ports: - "5103:5103" catalog.api: environment: - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word + #- ExternalCatalogBaseUrl=http://10.0.75.1:5101 #Local + - ExternalCatalogBaseUrl=http://13.88.8.119:5101 #Remote ports: - "5101:5101" ordering.api: environment: - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word - #- identityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. + - identityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. #- identityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker. - - identityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105. + #- identityUrl=http://10.0.75.1:5105 #Local: You need to open windows firewall at range 5100-5105. ports: - "5102:5102" @@ -59,9 +61,9 @@ services: environment: - SpaClient=http://localhost:5104 - ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word - #- MvcClient=http://13.88.8.119:5100 #Remote: VM Needs to have public access at 5105. + - MvcClient=http://13.88.8.119:5100 #Remote: VM Needs to have public access at 5105. #- MvcClient=http://localhost:5100 #Local: You need a entry in windows host file to run identity in local docker. - - MvcClient=http://10.0.75.1:5100 #Local: You need to open windows firewall at range 5100-5105. + #- MvcClient=http://10.0.75.1:5100 #Local: You need to open windows firewall at range 5100-5105. ports: - "5105:5105" diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index e67ff3276..d2fc39d95 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -1,6 +1,7 @@  namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers { + using Extensions.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; @@ -15,10 +16,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers public class CatalogController : ControllerBase { private readonly CatalogContext _context; + private readonly IOptions _settings; - public CatalogController(CatalogContext context) + public CatalogController(CatalogContext context, IOptions settings) { _context = context; + _settings = settings; } // GET api/v1/[controller]/items/[?pageSize=3&pageIndex=10] @@ -35,7 +38,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers .Take(pageSize) .ToListAsync(); - //itemsOnPage = ComposePicUri(itemsOnPage); + itemsOnPage = ComposePicUri(itemsOnPage); var model = new PaginatedItemsViewModel( pageIndex, pageSize, totalItems, itemsOnPage); @@ -59,7 +62,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers .Take(pageSize) .ToListAsync(); - //itemsOnPage = ComposePicUri(itemsOnPage); + itemsOnPage = ComposePicUri(itemsOnPage); var model = new PaginatedItemsViewModel( pageIndex, pageSize, totalItems, itemsOnPage); @@ -92,7 +95,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers .Take(pageSize) .ToListAsync(); - //itemsOnPage = ComposePicUri(itemsOnPage); + itemsOnPage = ComposePicUri(itemsOnPage); var model = new PaginatedItemsViewModel( pageIndex, pageSize, totalItems, itemsOnPage); @@ -123,9 +126,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers } private List ComposePicUri(List items) { + var baseUri = _settings.Value.ExternalCatalogBaseUrl; items.ForEach(x => { - x.PictureUri = x.PictureUri.Replace("localhost", Request.Host.Host); + x.PictureUri = x.PictureUri.Replace("http://externalcatalogbaseurltobereplaced", baseUri); }); return items; diff --git a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs index d2935fa1d..55ed81d23 100644 --- a/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs +++ b/src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs @@ -64,7 +64,8 @@ new CatalogBrand() { Brand = "Azure"}, new CatalogBrand() { Brand = ".NET" }, new CatalogBrand() { Brand = "Visual Studio" }, - new CatalogBrand() { Brand = "SQL Server" } + new CatalogBrand() { Brand = "SQL Server" }, + new CatalogBrand() { Brand = "Other" } }; } @@ -83,18 +84,18 @@ { return new List() { - 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" }, - 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" }, - 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" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/4" }, - 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" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/6" }, - 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" }, - 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" }, - 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" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/10" }, - 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" }, - new CatalogItem() { CatalogTypeId=2,CatalogBrandId=1, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/12" } + 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" }, + 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" }, + 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" }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/4" }, + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=5, Description = "Roslyn Red Sheet", Name = "Roslyn Red Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/5" }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=2, Description = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/6" }, + 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" }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Kudu Purple Sweatshirt", Name = "Kudu Purple Sweatshirt", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/8" }, + new CatalogItem() { CatalogTypeId=1,CatalogBrandId=5, Description = "Cup White Mug", Name = "Cup White Mug", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/9" }, + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/10" }, + new CatalogItem() { CatalogTypeId=3,CatalogBrandId=2, Description = "Cup Sheet", Name = "Cup Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/11" }, + new CatalogItem() { CatalogTypeId=2,CatalogBrandId=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12" } }; } } diff --git a/src/Services/Catalog/Catalog.API/Startup.cs b/src/Services/Catalog/Catalog.API/Startup.cs index 955131b86..70369056e 100644 --- a/src/Services/Catalog/Catalog.API/Startup.cs +++ b/src/Services/Catalog/Catalog.API/Startup.cs @@ -50,6 +50,8 @@ }); }); + services.Configure(Configuration); + // Add framework services. services.AddSwaggerGen(); services.ConfigureSwaggerGen(options => diff --git a/src/Services/Catalog/Catalog.API/settings.cs b/src/Services/Catalog/Catalog.API/settings.cs new file mode 100644 index 000000000..e73359302 --- /dev/null +++ b/src/Services/Catalog/Catalog.API/settings.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Microsoft.eShopOnContainers.Services.Catalog.API +{ + public class Settings + { + public string ExternalCatalogBaseUrl {get;set;} + } +} diff --git a/src/Services/Catalog/Catalog.API/settings.json b/src/Services/Catalog/Catalog.API/settings.json index f922656c7..e67fec713 100644 --- a/src/Services/Catalog/Catalog.API/settings.json +++ b/src/Services/Catalog/Catalog.API/settings.json @@ -1,5 +1,6 @@ { "ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word", + "ExternalCatalogBaseUrl": "http://localhost:5101", "Logging": { "IncludeScopes": false, "LogLevel": {