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

This commit is contained in:
Christian Arenas 2017-06-13 18:01:24 +02:00
parent 251cfa0845
commit 1881ed14ef
2 changed files with 11 additions and 13 deletions

View File

@ -10,8 +10,7 @@
[BsonRepresentation(BsonType.ObjectId)] [BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; } public string Id { get; set; }
public string UserId { get; set; } public string UserId { get; set; }
[BsonRepresentation(BsonType.ObjectId)] public int LocationId { get; set; }
public string LocationId { get; set; }
public DateTime UpdateDate { get; set; } public DateTime UpdateDate { get; set; }
} }
} }

View File

@ -1,5 +1,6 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
{ {
using Infrastructure.Repositories;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -18,10 +19,13 @@
public class CampaignsController : Controller public class CampaignsController : Controller
{ {
private readonly MarketingContext _context; private readonly MarketingContext _context;
private readonly IMarketingDataRepository _marketingDataRepository;
public CampaignsController(MarketingContext context) public CampaignsController(MarketingContext context,
IMarketingDataRepository marketingDataRepository)
{ {
_context = context; _context = context;
_marketingDataRepository = marketingDataRepository;
} }
[HttpGet] [HttpGet]
@ -117,19 +121,14 @@
} }
[HttpGet("user/{userId:guid}")] [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 var userLocation = await _marketingDataRepository.GetAsync(userId.ToString());
UserLocationDTO userLocationDto = new UserLocationDTO
{ var userLocationId = 1;
Id = "test",
LocationId = 1,
UpdateDate = DateTime.Now,
UserId = userId
};
var userLocationRule = await _context.Rules.OfType<UserLocationRule>().Include(c => c.Campaign) 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); return Ok(userLocationRule.Campaign);
} }