Skip to content

Commit 794d366

Browse files
committed
Merge branch 'feature/marketing-read-model-data' into marketingcampaign
# Conflicts: # src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs # src/Services/Location/Locations.API/Model/UserLocation.cs
2 parents 31fd93d + 9bf5670 commit 794d366

29 files changed

Lines changed: 426 additions & 40 deletions

docker-compose-windows.override.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,16 @@ services:
9595
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
9696
- EventBusConnection=rabbitmq
9797
ports:
98-
- "5109:80"
98+
- "5109:80"
99+
100+
marketing.api:
101+
environment:
102+
- ASPNETCORE_ENVIRONMENT=Development
103+
- ASPNETCORE_URLS=http://0.0.0.0:80
104+
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word
105+
- EventBusConnection=rabbitmq
106+
- MongoConnectionString=mongodb://nosql.data
107+
- MongoDatabase=MarketingDb
108+
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
109+
ports:
110+
- "5110:80"

docker-compose-windows.prod.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,19 @@ services:
7575
- BasketUrl=http://basket.api
7676
ports:
7777
- "5100:80"
78-
78+
79+
marketing.api:
80+
environment:
81+
- ASPNETCORE_ENVIRONMENT=Production
82+
- ASPNETCORE_URLS=http://0.0.0.0:80
83+
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word
84+
- EventBusConnection=rabbitmq
85+
- MongoConnectionString=mongodb://nosql.data
86+
- MongoDatabase=MarketingDb
87+
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
88+
ports:
89+
- "5110:80"
90+
7991
sql.data:
8092
environment:
8193
- SA_PASSWORD=Pass@word

docker-compose-windows.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,19 @@ services:
6161
dockerfile: Dockerfile
6262
depends_on:
6363
- nosql.data
64-
64+
- rabbitmq
65+
66+
marketing.api:
67+
image: eshop/marketing.api
68+
build:
69+
context: ./src/Services/Marketing/Marketing.API
70+
dockerfile: Dockerfile
71+
depends_on:
72+
- sql.data
73+
- nosql.data
74+
- identity.api
75+
- rabbitmq
76+
6577
sql.data:
6678
image: microsoft/mssql-server-windows
6779

docker-compose.override.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ services:
5858
- ASPNETCORE_ENVIRONMENT=Development
5959
- ASPNETCORE_URLS=http://0.0.0.0:80
6060
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word
61+
- MongoConnectionString=mongodb://nosql.data
62+
- MongoDatabase=MarketingDb
63+
- EventBusConnection=rabbitmq
6164
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
6265
ports:
6366
- "5110:80"

docker-compose.prod.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ services:
5959
- ASPNETCORE_ENVIRONMENT=Production
6060
- ASPNETCORE_URLS=http://0.0.0.0:80
6161
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word
62+
- MongoConnectionString=mongodb://nosql.data
63+
- MongoDatabase=MarketingDb
64+
- EventBusConnection=rabbitmq
6265
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
6366
ports:
6467
- "5110:80"

docker-compose.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ services:
5353
dockerfile: Dockerfile
5454
depends_on:
5555
- sql.data
56+
- nosql.data
5657
- identity.api
58+
- rabbitmq
5759

5860
webspa:
5961
image: eshop/webspa
@@ -112,3 +114,4 @@ services:
112114
dockerfile: Dockerfile
113115
depends_on:
114116
- nosql.data
117+
- rabbitmq

src/Services/Location/Locations.API/Controllers/LocationsController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public async Task<IActionResult> CreateOrUpdateUserLocation([FromBody]LocationRe
5454
{
5555
var userId = _identityService.GetUserIdentity();
5656
var result = await _locationsService.AddOrUpdateUserLocation(userId, newLocReq);
57+
5758
return result ?
5859
(IActionResult)Ok() :
5960
(IActionResult)BadRequest();

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

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,37 @@
88
using System.Linq;
99
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Exceptions;
1010
using System.Collections.Generic;
11+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
12+
using Microsoft.eShopOnContainers.Services.Locations.API.IntegrationEvents.Events;
1113

1214
public class LocationsService : ILocationsService
1315
{
14-
private ILocationsRepository _locationsRepository;
16+
private readonly ILocationsRepository _locationsRepository;
17+
private readonly IEventBus _eventBus;
1518

16-
public LocationsService(ILocationsRepository locationsRepository)
19+
public LocationsService(ILocationsRepository locationsRepository, IEventBus eventBus)
1720
{
1821
_locationsRepository = locationsRepository ?? throw new ArgumentNullException(nameof(locationsRepository));
22+
_eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus));
1923
}
2024

2125
public async Task<Locations> GetLocation(string locationId)
2226
{
2327
return await _locationsRepository.GetAsync(locationId);
2428
}
2529

26-
public async Task<UserLocation> GetUserLocation(string id)
30+
public async Task<UserLocation> GetUserLocation(string userId)
2731
{
28-
if (!Guid.TryParse(id, out Guid userId))
29-
{
30-
throw new ArgumentException("Not valid userId");
31-
}
32-
33-
return await _locationsRepository.GetUserLocationAsync(userId.ToString());
32+
return await _locationsRepository.GetUserLocationAsync(id);
3433
}
3534

3635
public async Task<List<Locations>> GetAllLocation()
3736
{
3837
return await _locationsRepository.GetLocationListAsync();
3938
}
4039

41-
public async Task<bool> AddOrUpdateUserLocation(string id, LocationRequest currentPosition)
42-
{
43-
if (!Guid.TryParse(id, out Guid userId))
44-
{
45-
throw new ArgumentException("Not valid userId");
46-
}
47-
40+
public async Task<bool> AddOrUpdateUserLocation(string userId, LocationRequest currentPosition)
41+
{
4842
// Get the list of ordered regions the user currently is within
4943
var currentUserAreaLocationList = await _locationsRepository.GetCurrentUserRegionsListAsync(currentPosition);
5044

@@ -55,14 +49,40 @@ public async Task<bool> AddOrUpdateUserLocation(string id, LocationRequest curre
5549

5650
// If current area found, then update user location
5751
var locationAncestors = new List<string>();
58-
var userLocation = await _locationsRepository.GetUserLocationAsync(userId.ToString());
52+
var userLocation = await _locationsRepository.GetUserLocationAsync(userId);
5953
userLocation = userLocation ?? new UserLocation();
6054
userLocation.UserId = userId;
6155
userLocation.LocationId = currentUserAreaLocationList[0].Id;
6256
userLocation.UpdateDate = DateTime.UtcNow;
6357
await _locationsRepository.UpdateUserLocationAsync(userLocation);
6458

59+
// Publish integration event to update marketing read data model
60+
// with the new locations updated
61+
PublishNewUserLocationPositionIntegrationEvent(userId, currentUserAreaLocationList);
62+
6563
return true;
6664
}
65+
66+
private void PublishNewUserLocationPositionIntegrationEvent(string userId, List<Locations> newLocations)
67+
{
68+
var newUserLocations = MapUserLocationDetails(newLocations);
69+
var @event = new UserLocationUpdatedIntegrationEvent(userId, newUserLocations);
70+
_eventBus.Publish(@event);
71+
}
72+
73+
private List<UserLocationDetails> MapUserLocationDetails(List<Locations> newLocations)
74+
{
75+
var result = new List<UserLocationDetails>();
76+
newLocations.ForEach(location => {
77+
result.Add(new UserLocationDetails()
78+
{
79+
LocationId = location.Id,
80+
Code = location.Code,
81+
Description = location.Description
82+
});
83+
});
84+
85+
return result;
86+
}
6787
}
6888
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
namespace Microsoft.eShopOnContainers.Services.Locations.API.IntegrationEvents.Events
2+
{
3+
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Events;
4+
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
5+
using System.Collections.Generic;
6+
7+
public class UserLocationUpdatedIntegrationEvent : IntegrationEvent
8+
{
9+
public string UserId { get; private set; }
10+
public List<UserLocationDetails> LocationList { get; private set; }
11+
12+
public UserLocationUpdatedIntegrationEvent(string userId, List<UserLocationDetails> locationList)
13+
{
14+
UserId = userId;
15+
LocationList = locationList;
16+
}
17+
}
18+
}

src/Services/Location/Locations.API/Locations.API.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<Folder Include="wwwroot\" />
1111
</ItemGroup>
1212
<ItemGroup>
13+
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.1.0" />
1314
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.0" />
1415
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
1516
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
@@ -37,5 +38,9 @@
3738
<ItemGroup>
3839
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
3940
</ItemGroup>
41+
<ItemGroup>
42+
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
43+
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
44+
</ItemGroup>
4045

4146
</Project>

0 commit comments

Comments
 (0)