From 41654878a70015b92ccfaa22ecca9bfcf77a21b0 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Tue, 13 Jun 2017 18:01:24 +0200 Subject: [PATCH] Add LocationId field to UserLocation and call GetAsync repository method from marketing controller --- .../Locations.API/Model/UserLocation.cs | 3 +-- .../Controllers/CampaignsController.cs | 21 +++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/Services/Location/Locations.API/Model/UserLocation.cs b/src/Services/Location/Locations.API/Model/UserLocation.cs index 1d1b3d690..4686bd006 100644 --- a/src/Services/Location/Locations.API/Model/UserLocation.cs +++ b/src/Services/Location/Locations.API/Model/UserLocation.cs @@ -10,8 +10,7 @@ [BsonRepresentation(BsonType.ObjectId)] public string Id { get; set; } public string UserId { get; set; } - [BsonRepresentation(BsonType.ObjectId)] - public string LocationId { get; set; } + public int LocationId { get; set; } public DateTime UpdateDate { get; set; } } } diff --git a/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs b/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs index fe72a286c..db09edb62 100644 --- a/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs +++ b/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs @@ -1,5 +1,6 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers { + using Infrastructure.Repositories; using Microsoft.AspNetCore.Mvc; using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; using System.Threading.Tasks; @@ -18,10 +19,13 @@ public class CampaignsController : Controller { private readonly MarketingContext _context; + private readonly IMarketingDataRepository _marketingDataRepository; - public CampaignsController(MarketingContext context) + public CampaignsController(MarketingContext context, + IMarketingDataRepository marketingDataRepository) { _context = context; + _marketingDataRepository = marketingDataRepository; } [HttpGet] @@ -117,19 +121,14 @@ } [HttpGet("user/{userId:guid}")] - public async Task GetCampaignByUserId(Guid userId) + public async Task GetCampaignsByUserId(Guid userId) { - //TODO: Call data read model to get userLocation from userId - UserLocationDTO userLocationDto = new UserLocationDTO - { - Id = "test", - LocationId = 1, - UpdateDate = DateTime.Now, - UserId = userId - }; + var userLocation = await _marketingDataRepository.GetAsync(userId.ToString()); + + var userLocationId = 1; var userLocationRule = await _context.Rules.OfType().Include(c => c.Campaign) - .FirstOrDefaultAsync(c => c.LocationId == userLocationDto.LocationId); + .FirstOrDefaultAsync(c => c.LocationId == userLocationId); return Ok(userLocationRule.Campaign); }