Browse Source

Add LocationId field to UserLocation and call GetAsync repository method from marketing controller

pull/223/head
Christian Arenas 7 years ago
parent
commit
1881ed14ef
2 changed files with 11 additions and 13 deletions
  1. +1
    -2
      src/Services/Location/Locations.API/Model/UserLocation.cs
  2. +10
    -11
      src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs

+ 1
- 2
src/Services/Location/Locations.API/Model/UserLocation.cs View File

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

+ 10
- 11
src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs View File

@ -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<IActionResult> GetCampaignByUserId(Guid userId)
public async Task<IActionResult> 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<UserLocationRule>().Include(c => c.Campaign)
.FirstOrDefaultAsync(c => c.LocationId == userLocationDto.LocationId);
.FirstOrDefaultAsync(c => c.LocationId == userLocationId);
return Ok(userLocationRule.Campaign);
}


Loading…
Cancel
Save