Catalog Seed: Dynamic host url for image pics

This commit is contained in:
PLAINCONCEPTS\ccanizares 2017-01-09 10:33:43 +01:00
parent bbb6303f2a
commit 93bbd6516b
6 changed files with 50 additions and 28 deletions

View File

@ -13,8 +13,8 @@ services:
environment: environment:
- CatalogUrl=http://catalog.api:5101 - CatalogUrl=http://catalog.api:5101
- OrderingUrl=http://ordering.api:5102 - 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://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.
#- IdentityUrl=http://identity.service:5105 #Local: You need a entry in windows host file to run identity in local docker. #- 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 - BasketUrl=http://basket.api:5103
ports: ports:
@ -24,9 +24,9 @@ services:
environment: environment:
- CatalogUrl=http://catalog.api:5101 - CatalogUrl=http://catalog.api:5101
- OrderingUrl=http://ordering.api:5102 - 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://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 - BasketUrl=http://basket.api:5103
ports: ports:
- "5104:5104" - "5104:5104"
@ -34,24 +34,26 @@ services:
basket.api: basket.api:
environment: environment:
- ConnectionString=basket.data - 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://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: ports:
- "5103:5103" - "5103:5103"
catalog.api: catalog.api:
environment: environment:
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word - 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: ports:
- "5101:5101" - "5101:5101"
ordering.api: ordering.api:
environment: environment:
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word - 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://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: ports:
- "5102:5102" - "5102:5102"
@ -59,9 +61,9 @@ services:
environment: environment:
- SpaClient=http://localhost:5104 - SpaClient=http://localhost:5104
- ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word - 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://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: ports:
- "5105:5105" - "5105:5105"

View File

@ -1,6 +1,7 @@
 
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
{ {
using Extensions.Options;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure; using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
@ -15,10 +16,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
public class CatalogController : ControllerBase public class CatalogController : ControllerBase
{ {
private readonly CatalogContext _context; private readonly CatalogContext _context;
private readonly IOptions<Settings> _settings;
public CatalogController(CatalogContext context) public CatalogController(CatalogContext context, IOptions<Settings> settings)
{ {
_context = context; _context = context;
_settings = settings;
} }
// GET api/v1/[controller]/items/[?pageSize=3&pageIndex=10] // GET api/v1/[controller]/items/[?pageSize=3&pageIndex=10]
@ -35,7 +38,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
.Take(pageSize) .Take(pageSize)
.ToListAsync(); .ToListAsync();
//itemsOnPage = ComposePicUri(itemsOnPage); itemsOnPage = ComposePicUri(itemsOnPage);
var model = new PaginatedItemsViewModel<CatalogItem>( var model = new PaginatedItemsViewModel<CatalogItem>(
pageIndex, pageSize, totalItems, itemsOnPage); pageIndex, pageSize, totalItems, itemsOnPage);
@ -59,7 +62,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
.Take(pageSize) .Take(pageSize)
.ToListAsync(); .ToListAsync();
//itemsOnPage = ComposePicUri(itemsOnPage); itemsOnPage = ComposePicUri(itemsOnPage);
var model = new PaginatedItemsViewModel<CatalogItem>( var model = new PaginatedItemsViewModel<CatalogItem>(
pageIndex, pageSize, totalItems, itemsOnPage); pageIndex, pageSize, totalItems, itemsOnPage);
@ -92,7 +95,7 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
.Take(pageSize) .Take(pageSize)
.ToListAsync(); .ToListAsync();
//itemsOnPage = ComposePicUri(itemsOnPage); itemsOnPage = ComposePicUri(itemsOnPage);
var model = new PaginatedItemsViewModel<CatalogItem>( var model = new PaginatedItemsViewModel<CatalogItem>(
pageIndex, pageSize, totalItems, itemsOnPage); pageIndex, pageSize, totalItems, itemsOnPage);
@ -123,9 +126,10 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
} }
private List<CatalogItem> ComposePicUri(List<CatalogItem> items) { private List<CatalogItem> ComposePicUri(List<CatalogItem> items) {
var baseUri = _settings.Value.ExternalCatalogBaseUrl;
items.ForEach(x => items.ForEach(x =>
{ {
x.PictureUri = x.PictureUri.Replace("localhost", Request.Host.Host); x.PictureUri = x.PictureUri.Replace("http://externalcatalogbaseurltobereplaced", baseUri);
}); });
return items; return items;

View File

@ -64,7 +64,8 @@
new CatalogBrand() { Brand = "Azure"}, new CatalogBrand() { Brand = "Azure"},
new CatalogBrand() { Brand = ".NET" }, new CatalogBrand() { Brand = ".NET" },
new CatalogBrand() { Brand = "Visual Studio" }, 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<CatalogItem>() return new List<CatalogItem>()
{ {
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=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://localhost:5101/api/v1/pic/2" }, 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=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=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=1, Description = ".NET Foundation Sweatshirt", Name = ".NET Foundation Sweatshirt", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/4" }, 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=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=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=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 = ".NET Blue Sweatshirt", Name = ".NET Blue Sweatshirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/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=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=1, Description = ".NET Purple Sweatshirt", Name = ".NET Purple Sweatshirt", Price = 8.5M, PictureUri = "http://localhost:5101/api/v1/pic/8" }, 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=1, Description = ".NET T White Mug", Name = ".NET T White Mug", Price = 12, PictureUri = "http://localhost:5101/api/v1/pic/9" }, 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" },
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=3,CatalogBrandId=2, Description = ".NET Foundation Sheet", Name = ".NET Foundation Sheet", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/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=3,CatalogBrandId=2, Description = "Cup<T> Sheet", Name = "Cup<T> Sheet", Price = 8.5M, PictureUri = "http://externalcatalogbaseurltobereplaced/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=5, Description = "Prism White TShirt", Name = "Prism White TShirt", Price = 12, PictureUri = "http://externalcatalogbaseurltobereplaced/api/v1/pic/12" }
}; };
} }
} }

View File

@ -50,6 +50,8 @@
}); });
}); });
services.Configure<Settings>(Configuration);
// Add framework services. // Add framework services.
services.AddSwaggerGen(); services.AddSwaggerGen();
services.ConfigureSwaggerGen(options => services.ConfigureSwaggerGen(options =>

View File

@ -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;}
}
}

View File

@ -1,5 +1,6 @@
{ {
"ConnectionString": "Server=tcp:127.0.0.1,5433;Initial Catalog=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word", "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": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"LogLevel": { "LogLevel": {