Skip to content

Commit 480723e

Browse files
committed
Merge branch 'dev' into eShopOnServiceFabric-Win
2 parents 2f47258 + cecdc40 commit 480723e

16 files changed

Lines changed: 430 additions & 40 deletions

File tree

docker-compose.override.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ services:
102102
- IdentityUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
103103
- BasketUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5103
104104
- MarketingUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5110
105+
- LocationsUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5109
105106
- CatalogUrlHC=http://catalog.api/hc
106107
- OrderingUrlHC=http://ordering.api/hc
107108
- IdentityUrlHC=http://identity.api/hc #Local: Use ${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}, if using external IP or DNS name from browser.
@@ -118,6 +119,7 @@ services:
118119
- CatalogUrl=http://catalog.api
119120
- OrderingUrl=http://ordering.api
120121
- BasketUrl=http://basket.api
122+
- LocationsUrl=http://locations.api
121123
- IdentityUrl=http://10.0.75.1:5105
122124
- MarketingUrl=http://marketing.api #Local: Use 10.0.75.1 in a "Docker for Windows" environment, if using "localhost" from browser.
123125
#Remote: Use ${ESHOP_EXTERNAL_DNS_NAME_OR_IP} if using external IP or DNS name from browser.

src/Services/Location/Locations.API/Infrastructure/LocationsContextSeed.cs

Lines changed: 184 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,38 @@ public static async Task SeedAsync(IApplicationBuilder applicationBuilder, ILogg
2323
if (!ctx.Locations.Database.GetCollection<Locations>(nameof(Locations)).AsQueryable().Any())
2424
{
2525
await SetIndexes();
26-
await SetUSLocations();
26+
await SetNorthAmerica();
27+
await SetSouthAmerica();
28+
await SetAfrica();
29+
await SetEurope();
30+
await SetAsia();
31+
await SetAustralia();
2732
await SetBarcelonaLocations();
2833
}
2934
}
3035

31-
static async Task SetUSLocations()
36+
static async Task SetNorthAmerica()
3237
{
3338
var us = new Locations()
3439
{
40+
Code = "NA",
41+
Description = "North America",
42+
LocationId = 1
43+
};
44+
us.SetLocation(-103.219329, 48.803281);
45+
us.SetArea(GetNorthAmericaPoligon());
46+
await ctx.Locations.InsertOneAsync(us);
47+
await SetUSLocations(us.Id);
48+
}
49+
50+
static async Task SetUSLocations(string parentId)
51+
{
52+
var us = new Locations()
53+
{
54+
Parent_Id = parentId,
3555
Code = "US",
3656
Description = "United States",
37-
LocationId = 1
57+
LocationId = 2
3858
};
3959
us.SetLocation(-101.357386, 41.650455);
4060
us.SetArea(GetUSPoligon());
@@ -49,7 +69,7 @@ static async Task SetWashingtonLocations(string parentId)
4969
Parent_Id = parentId,
5070
Code = "WHT",
5171
Description = "Washington",
52-
LocationId = 2
72+
LocationId = 3
5373
};
5474
wht.SetLocation(-119.542781, 47.223652);
5575
wht.SetArea(GetWashingtonPoligon());
@@ -65,7 +85,7 @@ static async Task SetSeattleLocations(string parentId)
6585
Parent_Id = parentId,
6686
Code = "SEAT",
6787
Description = "Seattle",
68-
LocationId = 3
88+
LocationId = 4
6989
};
7090
stl.SetArea(GetSeattlePoligon());
7191
stl.SetLocation(-122.330747, 47.603111);
@@ -79,7 +99,7 @@ static async Task SetRedmondLocations(string parentId)
7999
Parent_Id = parentId,
80100
Code = "REDM",
81101
Description = "Redmond",
82-
LocationId = 4
102+
LocationId = 5
83103
};
84104
rdm.SetLocation(-122.122887, 47.674961);
85105
rdm.SetArea(GetRedmondPoligon());
@@ -92,13 +112,77 @@ static async Task SetBarcelonaLocations()
92112
{
93113
Code = "BCN",
94114
Description = "Barcelona",
95-
LocationId = 5
115+
LocationId = 6
96116
};
97117
bcn.SetLocation(2.156453, 41.395226);
98118
bcn.SetArea(GetBarcelonaPoligon());
99119
await ctx.Locations.InsertOneAsync(bcn);
100120
}
101121

122+
static async Task SetSouthAmerica()
123+
{
124+
var sa = new Locations()
125+
{
126+
Code = "SA",
127+
Description = "South America",
128+
LocationId = 7
129+
};
130+
sa.SetLocation(-60.328704, -16.809748);
131+
sa.SetArea(GetSouthAmericaPoligon());
132+
await ctx.Locations.InsertOneAsync(sa);
133+
}
134+
135+
static async Task SetAfrica()
136+
{
137+
var afc = new Locations()
138+
{
139+
Code = "AFC",
140+
Description = "Africa",
141+
LocationId = 8
142+
};
143+
afc.SetLocation(19.475383, 13.063667);
144+
afc.SetArea(GetAfricaPoligon());
145+
await ctx.Locations.InsertOneAsync(afc);
146+
}
147+
148+
static async Task SetEurope()
149+
{
150+
var eu = new Locations()
151+
{
152+
Code = "EU",
153+
Description = "Europe",
154+
LocationId = 9
155+
};
156+
eu.SetLocation(13.147258, 49.947844);
157+
eu.SetArea(GetEuropePoligon());
158+
await ctx.Locations.InsertOneAsync(eu);
159+
}
160+
161+
static async Task SetAsia()
162+
{
163+
var asa = new Locations()
164+
{
165+
Code = "AS",
166+
Description = "Asia",
167+
LocationId = 10
168+
};
169+
asa.SetLocation(97.522257, 56.069107);
170+
asa.SetArea(GetAsiaPoligon());
171+
await ctx.Locations.InsertOneAsync(asa);
172+
}
173+
174+
static async Task SetAustralia()
175+
{
176+
var aus = new Locations()
177+
{
178+
Code = "AUS",
179+
Description = "Australia",
180+
LocationId = 11
181+
};
182+
aus.SetLocation(133.733195, -25.010726);
183+
aus.SetArea(GetAustraliaPoligon());
184+
await ctx.Locations.InsertOneAsync(aus);
185+
}
102186

103187
static async Task SetIndexes()
104188
{
@@ -108,6 +192,99 @@ static async Task SetIndexes()
108192
await ctx.Locations.Indexes.CreateOneAsync(keys);
109193
}
110194

195+
static List<GeoJson2DGeographicCoordinates> GetNorthAmericaPoligon()
196+
{
197+
return new List<GeoJson2DGeographicCoordinates>()
198+
{
199+
new GeoJson2DGeographicCoordinates(-168.07786, 68.80277),
200+
new GeoJson2DGeographicCoordinates(-119.60378, 32.7561),
201+
new GeoJson2DGeographicCoordinates(-116.01966, 28.94642),
202+
new GeoJson2DGeographicCoordinates(-98.52265, 14.49378),
203+
new GeoJson2DGeographicCoordinates(-71.18188, 34.96278),
204+
new GeoJson2DGeographicCoordinates(-51.97606, 48.24377),
205+
new GeoJson2DGeographicCoordinates(-75.39806, 72.93141),
206+
new GeoJson2DGeographicCoordinates(-168.07786, 68.80277)
207+
};
208+
}
209+
210+
static List<GeoJson2DGeographicCoordinates> GetSouthAmericaPoligon()
211+
{
212+
return new List<GeoJson2DGeographicCoordinates>()
213+
{
214+
new GeoJson2DGeographicCoordinates(-91.43724, 13.29007),
215+
new GeoJson2DGeographicCoordinates(-87.96315, -27.15081),
216+
new GeoJson2DGeographicCoordinates(-78.75404, -50.71852),
217+
new GeoJson2DGeographicCoordinates(-59.14765, -58.50773),
218+
new GeoJson2DGeographicCoordinates(-50.08813, -42.22419),
219+
new GeoJson2DGeographicCoordinates(-37.21044, -22.56725),
220+
new GeoJson2DGeographicCoordinates(-36.61675, -0.38594),
221+
new GeoJson2DGeographicCoordinates(-44.46056, -16.6746),
222+
new GeoJson2DGeographicCoordinates(-91.43724, 13.29007),
223+
};
224+
}
225+
226+
static List<GeoJson2DGeographicCoordinates> GetAfricaPoligon()
227+
{
228+
return new List<GeoJson2DGeographicCoordinates>()
229+
{
230+
new GeoJson2DGeographicCoordinates(-12.68724, 34.05892),
231+
new GeoJson2DGeographicCoordinates(-18.33301, 20.77313),
232+
new GeoJson2DGeographicCoordinates(-14.13503, 6.21292),
233+
new GeoJson2DGeographicCoordinates(1.40221, -14.23693),
234+
new GeoJson2DGeographicCoordinates(22.41485, -35.55408),
235+
new GeoJson2DGeographicCoordinates(51.86499, -25.39831),
236+
new GeoJson2DGeographicCoordinates(53.49269, 4.59405),
237+
new GeoJson2DGeographicCoordinates(35.102, 26.14685),
238+
new GeoJson2DGeographicCoordinates(21.63319, 33.75767),
239+
new GeoJson2DGeographicCoordinates(6.58235, 37.05665),
240+
new GeoJson2DGeographicCoordinates(-12.68724, 34.05892),
241+
};
242+
}
243+
244+
static List<GeoJson2DGeographicCoordinates> GetEuropePoligon()
245+
{
246+
return new List<GeoJson2DGeographicCoordinates>()
247+
{
248+
new GeoJson2DGeographicCoordinates(-11.73143, 35.27646),
249+
new GeoJson2DGeographicCoordinates(-10.84462, 35.25123),
250+
new GeoJson2DGeographicCoordinates(-10.09927, 35.26833),
251+
new GeoJson2DGeographicCoordinates(49.00838, 36.56984),
252+
new GeoJson2DGeographicCoordinates(36.63837, 71.69807),
253+
new GeoJson2DGeographicCoordinates(-10.88788, 61.13851),
254+
new GeoJson2DGeographicCoordinates(-11.73143, 35.27646),
255+
};
256+
}
257+
258+
static List<GeoJson2DGeographicCoordinates> GetAsiaPoligon()
259+
{
260+
return new List<GeoJson2DGeographicCoordinates>()
261+
{
262+
new GeoJson2DGeographicCoordinates(31.1592, 45.91629),
263+
new GeoJson2DGeographicCoordinates(32.046, 45.89479),
264+
new GeoJson2DGeographicCoordinates(62.32261, -4.45013),
265+
new GeoJson2DGeographicCoordinates(154.47713, 35.14525),
266+
new GeoJson2DGeographicCoordinates(-166.70788, 68.62211),
267+
new GeoJson2DGeographicCoordinates(70.38837, 75.89335),
268+
new GeoJson2DGeographicCoordinates(32.00274, 67.23428),
269+
new GeoJson2DGeographicCoordinates(31.1592, 45.91629),
270+
};
271+
}
272+
273+
static List<GeoJson2DGeographicCoordinates> GetAustraliaPoligon()
274+
{
275+
return new List<GeoJson2DGeographicCoordinates>()
276+
{
277+
new GeoJson2DGeographicCoordinates(100.76857, -45.74117),
278+
new GeoJson2DGeographicCoordinates(101.65538, -45.76273),
279+
new GeoJson2DGeographicCoordinates(167.08823, -50.66317),
280+
new GeoJson2DGeographicCoordinates(174.16463, -34.62579),
281+
new GeoJson2DGeographicCoordinates(160.94837, -5.01004),
282+
new GeoJson2DGeographicCoordinates(139.29462, -7.86376),
283+
new GeoJson2DGeographicCoordinates(101.61212, -11.44654),
284+
new GeoJson2DGeographicCoordinates(100.76857, -45.74117),
285+
};
286+
}
287+
111288
static List<GeoJson2DGeographicCoordinates> GetUSPoligon()
112289
{
113290
return new List<GeoJson2DGeographicCoordinates>()

src/Services/Location/Locations.API/Startup.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Autofac;
22
using Autofac.Extensions.DependencyInjection;
3+
using Microsoft.AspNetCore.Authentication.JwtBearer;
34
using Microsoft.AspNetCore.Builder;
45
using Microsoft.AspNetCore.Hosting;
56
using Microsoft.AspNetCore.Http;
@@ -169,13 +170,17 @@ private void ConfigureAuthService(IServiceCollection services)
169170
// prevent from mapping "sub" claim to nameidentifier.
170171
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
171172

172-
services.AddAuthentication()
173-
.AddJwtBearer(options =>
174-
{
175-
options.Authority = Configuration.GetValue<string>("IdentityUrl");
176-
options.Audience = "locations";
177-
options.RequireHttpsMetadata = false;
178-
});
173+
services.AddAuthentication(options =>
174+
{
175+
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
176+
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
177+
})
178+
.AddJwtBearer(options =>
179+
{
180+
options.Authority = Configuration.GetValue<string>("IdentityUrl");
181+
options.Audience = "locations";
182+
options.RequireHttpsMetadata = false;
183+
});
179184
}
180185

181186
protected virtual void ConfigureAuth(IApplicationBuilder app)

src/Services/Marketing/Marketing.API/Startup.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Infrastructure.Services;
2222
using IntegrationEvents.Events;
2323
using Marketing.API.IntegrationEvents.Handlers;
24+
using Microsoft.AspNetCore.Authentication.JwtBearer;
2425
using Microsoft.EntityFrameworkCore.Diagnostics;
2526
using RabbitMQ.Client;
2627
using Swashbuckle.AspNetCore.Swagger;
@@ -199,8 +200,12 @@ private void ConfigureAuthService(IServiceCollection services)
199200
// prevent from mapping "sub" claim to nameidentifier.
200201
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
201202

202-
services.AddAuthentication()
203-
.AddJwtBearer(options =>
203+
services.AddAuthentication(options=>
204+
{
205+
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
206+
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
207+
208+
}).AddJwtBearer(options =>
204209
{
205210
options.Authority = Configuration.GetValue<string>("IdentityUrl");
206211
options.Audience = "marketing";

src/Web/WebMVC/AppSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class AppSettings
1212
public string OrderingUrl { get; set; }
1313
public string BasketUrl { get; set; }
1414
public string MarketingUrl { get; set; }
15+
public string LocationsUrl { get; set; }
1516
public bool ActivateCampaignDetailFunction { get; set; }
1617
public Logging Logging { get; set; }
1718
public bool UseCustomizationData { get; set; }

src/Web/WebMVC/Controllers/CampaignsController.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
using Microsoft.EntityFrameworkCore.Query.Internal;
2-
using WebMVC.ViewModels;
3-
41
namespace Microsoft.eShopOnContainers.WebMVC.Controllers
52
{
63
using AspNetCore.Authorization;
74
using AspNetCore.Mvc;
5+
using global::WebMVC.Models;
6+
using global::WebMVC.Services;
7+
using global::WebMVC.ViewModels;
8+
using Microsoft.Extensions.Options;
89
using Services;
9-
using ViewModels;
10-
using System.Threading.Tasks;
1110
using System;
11+
using System.Threading.Tasks;
12+
using ViewModels;
1213
using ViewModels.Pagination;
13-
using global::WebMVC.ViewModels;
14-
using Microsoft.Extensions.Options;
1514

1615
[Authorize]
1716
public class CampaignsController : Controller
1817
{
1918
private readonly ICampaignService _campaignService;
19+
private readonly ILocationService _locationService;
2020
private readonly AppSettings _settings;
2121

22-
public CampaignsController(ICampaignService campaignService, IOptionsSnapshot<AppSettings> settings)
22+
public CampaignsController(ICampaignService campaignService, ILocationService locationService, IOptionsSnapshot<AppSettings> settings)
2323
{
2424
_campaignService = campaignService;
2525
_settings = settings.Value;
26+
_locationService = locationService;
2627
}
2728

2829
public async Task<IActionResult> Index(int page = 0, int pageSize = 10)
@@ -76,5 +77,23 @@ public async Task<IActionResult> Details(int id)
7677

7778
return View(campaign);
7879
}
80+
81+
[HttpPost]
82+
public async Task<IActionResult> CreateNewUserLocation(CampaignViewModel model)
83+
{
84+
if (ModelState.IsValid)
85+
{
86+
var location = new LocationDTO()
87+
{
88+
Longitude = model.Lon,
89+
Latitude = model.Lat
90+
};
91+
await _locationService.CreateOrUpdateUserLocation(location);
92+
93+
return RedirectToAction(nameof(Index));
94+
}
95+
96+
return View(nameof(Index), model);
97+
}
7998
}
8099
}

0 commit comments

Comments
 (0)