Skip to content

Commit 432994d

Browse files
committed
Create GetCampaignByUserId in CampaignsController
1 parent 4a60d97 commit 432994d

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
using Microsoft.eShopOnContainers.Services.Marketing.API.Dto;
99
using System.Collections.Generic;
1010
using Microsoft.AspNetCore.Authorization;
11+
using System;
12+
using System.Net.Http;
13+
using System.Linq;
14+
using System.Net.Http.Headers;
1115

1216
[Route("api/v1/[controller]")]
1317
[Authorize]
@@ -112,6 +116,23 @@ public async Task<IActionResult> Delete(int id)
112116
return NoContent();
113117
}
114118

119+
[HttpGet("user/{userId:guid}")]
120+
public async Task<IActionResult> GetCampaignByUserId(Guid userId)
121+
{
122+
//TODO: Call data read model to get userLocation from userId
123+
UserLocationDTO userLocationDto = new UserLocationDTO
124+
{
125+
Id = "test",
126+
LocationId = 1,
127+
UpdateDate = DateTime.Now,
128+
UserId = userId
129+
};
130+
131+
var userLocationRule = await _context.Rules.OfType<UserLocationRule>().Include(c => c.Campaign)
132+
.FirstOrDefaultAsync(c => c.LocationId == userLocationDto.LocationId);
133+
134+
return Ok(userLocationRule.Campaign);
135+
}
115136

116137

117138
private List<CampaignDTO> MapCampaignModelListToDtoList(List<Campaign> campaignList)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Dto
4+
{
5+
public class UserLocationDTO
6+
{
7+
public string Id { get; set; }
8+
public Guid UserId { get; set; }
9+
public int LocationId { get; set; }
10+
public DateTime UpdateDate { get; set; }
11+
}
12+
}

0 commit comments

Comments
 (0)