From f0f88aee98a431f6e744f8c28ffb0ee580da2c41 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 11 Jul 2017 12:43:06 +0200 Subject: [PATCH] Add PicBaseUrl with a replaced parameter --- docker-compose.override.yml | 4 ++-- docker-compose.prod.yml | 4 ++-- .../Catalog.API/Controllers/CatalogController.cs | 5 ++--- .../Catalog/Catalog.API/Controllers/PicController.cs | 10 +++++----- src/Services/Catalog/Catalog.API/settings.json | 2 +- .../Marketing.API/Controllers/CampaignsController.cs | 2 +- src/Services/Marketing/Marketing.API/appsettings.json | 5 +++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index ca962be9b..8d0880f92 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -29,7 +29,7 @@ services: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://0.0.0.0:80 - ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word} - - PicBaseUrl=${ESHOP_AZURE_STORAGE_CATALOG:-http://localhost:5101/api/v1/pic/} #Local: You need to open your local dev-machine firewall at range 5100-5110. + - PicBaseUrl=${ESHOP_AZURE_STORAGE_CATALOG:-http://localhost:5101/api/v1/catalog/items/[0]/pic/} #Local: You need to open your local dev-machine firewall at range 5100-5110. - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} - AzureStorageAccountName=${ESHOP_AZURE_STORAGE_CATALOG_NAME} - AzureStorageAccountKey=${ESHOP_AZURE_STORAGE_CATALOG_KEY} @@ -70,7 +70,7 @@ services: - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5110. - CampaignDetailFunctionUri=${ESHOP_AZUREFUNC_CAMPAIGN_DETAILS_URI} - - PicBaseUrl=${ESHOP_AZURE_STORAGE_MARKETING:-http://localhost:5110/api/v1/pic/} + - PicBaseUrl=${ESHOP_AZURE_STORAGE_MARKETING:-http://localhost:5110/api/v1/campaigns/[0]/pic/} - AzureStorageAccountName=${ESHOP_AZURE_STORAGE_MARKETING_NAME} - AzureStorageAccountKey=${ESHOP_AZURE_STORAGE_MARKETING_KEY} ports: diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 8c1628ffb..fa2f1ccd8 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -34,7 +34,7 @@ services: - ASPNETCORE_ENVIRONMENT=Production ASPNETCORE_URLS=http://0.0.0.0:80 - ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word} - - PicBaseUrl=${ESHOP_AZURE_STORAGE_CATALOG:-http://localhost:5101/api/v1/pic/} #Local: You need to open your local dev-machine firewall at range 5100-5110. + - PicBaseUrl=${ESHOP_AZURE_STORAGE_CATALOG} #Local: You need to open your local dev-machine firewall at range 5100-5110. - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} - AzureStorageAccountName=${ESHOP_AZURE_STORAGE_CATALOG_NAME} - AzureStorageAccountKey=${ESHOP_AZURE_STORAGE_CATALOG_KEY} @@ -75,7 +75,7 @@ services: - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5110. - CampaignDetailFunctionUri=${ESHOP_AZUREFUNC_CAMPAIGN_DETAILS_URI} - - PicBaseUrl=${ESHOP_AZURE_STORAGE_MARKETING:-http://localhost:5110/api/v1/pic/} + - PicBaseUrl=${ESHOP_AZURE_STORAGE_MARKETING} - AzureStorageAccountName=${ESHOP_AZURE_STORAGE_MARKETING_NAME} - AzureStorageAccountKey=${ESHOP_AZURE_STORAGE_MARKETING_KEY} ports: diff --git a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs index ca1ef9e3b..fe52b9128 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/CatalogController.cs @@ -232,13 +232,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers private List ChangeUriPlaceholder(List items) { var baseUri = _settings.PicBaseUrl; - + items.ForEach(catalogItem => { catalogItem.PictureUri = _settings.AzureStorageEnabled ? baseUri + catalogItem.PictureFileName - : baseUri + catalogItem.Id; - + : baseUri.Replace("[0]", catalogItem.Id.ToString()); }); return items; diff --git a/src/Services/Catalog/Catalog.API/Controllers/PicController.cs b/src/Services/Catalog/Catalog.API/Controllers/PicController.cs index 75029dc95..7043ce9f7 100644 --- a/src/Services/Catalog/Catalog.API/Controllers/PicController.cs +++ b/src/Services/Catalog/Catalog.API/Controllers/PicController.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers { - [Route("api/v1/[controller]")] public class PicController : Controller { private readonly IHostingEnvironment _env; @@ -22,17 +21,18 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers _catalogContext = catalogContext; } - [HttpGet("{id}")] + [HttpGet] + [Route("api/v1/catalog/items/{catalogItemId:int}/pic")] // GET: // - public async Task GetImage(int id) + public async Task GetImage(int catalogItemId) { - if (id <= 0) + if (catalogItemId <= 0) { return BadRequest(); } var item = await _catalogContext.CatalogItems - .SingleOrDefaultAsync(ci => ci.Id == id); + .SingleOrDefaultAsync(ci => ci.Id == catalogItemId); if (item != null) { diff --git a/src/Services/Catalog/Catalog.API/settings.json b/src/Services/Catalog/Catalog.API/settings.json index b6dc3b5f7..dafeca845 100644 --- a/src/Services/Catalog/Catalog.API/settings.json +++ b/src/Services/Catalog/Catalog.API/settings.json @@ -1,6 +1,6 @@ { "ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word", - "PicBaseUrl": "http://localhost:5101", + "PicBaseUrl": "http://localhost:5101/api/v1/catalog/items/[0]/pic/", "UseCustomizationData": false, "Logging": { "IncludeScopes": false, diff --git a/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs b/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs index ff7abcd45..146802626 100644 --- a/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs +++ b/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs @@ -221,7 +221,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers return _settings.AzureStorageEnabled ? baseUri + campaign.PictureName - : baseUri + campaign.Id; + : baseUri.Replace("[0]", campaign.Id.ToString()); } } } \ No newline at end of file diff --git a/src/Services/Marketing/Marketing.API/appsettings.json b/src/Services/Marketing/Marketing.API/appsettings.json index 0137a2ae8..21aae065a 100644 --- a/src/Services/Marketing/Marketing.API/appsettings.json +++ b/src/Services/Marketing/Marketing.API/appsettings.json @@ -5,12 +5,13 @@ "Default": "Warning" } }, - "ConnectionString": "127.0.0.1", + "ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word", "MongoConnectionString": "mongodb://nosql.data", "MongoDatabase": "MarketingDb", "IdentityUrl": "http://localhost:5105", - "ExternalCatalogBaseUrl": "http://localhost:5110", + "PicBaseUrl": "http://localhost:5110/api/v1/campaigns/[0]/pic/", "AzureServiceBusEnabled": false, "SubscriptionClientName": "Marketing", "AzureStorageEnabled": false + }