diff --git a/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs b/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs index f3dde55ef..fe72a286c 100644 --- a/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs +++ b/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs @@ -8,6 +8,10 @@ using Microsoft.eShopOnContainers.Services.Marketing.API.Dto; using System.Collections.Generic; using Microsoft.AspNetCore.Authorization; + using System; + using System.Net.Http; + using System.Linq; + using System.Net.Http.Headers; [Route("api/v1/[controller]")] [Authorize] @@ -112,6 +116,23 @@ return NoContent(); } + [HttpGet("user/{userId:guid}")] + public async Task GetCampaignByUserId(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 userLocationRule = await _context.Rules.OfType().Include(c => c.Campaign) + .FirstOrDefaultAsync(c => c.LocationId == userLocationDto.LocationId); + + return Ok(userLocationRule.Campaign); + } private List MapCampaignModelListToDtoList(List campaignList) diff --git a/src/Services/Marketing/Marketing.API/Dto/UserLocationDTO.cs b/src/Services/Marketing/Marketing.API/Dto/UserLocationDTO.cs new file mode 100644 index 000000000..aee043f82 --- /dev/null +++ b/src/Services/Marketing/Marketing.API/Dto/UserLocationDTO.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +namespace Microsoft.eShopOnContainers.Services.Marketing.API.Dto +{ + public class UserLocationDTO + { + public string Id { get; set; } + public Guid UserId { get; set; } + public int LocationId { get; set; } + public DateTime UpdateDate { get; set; } + } +} \ No newline at end of file