Skip to content

Commit

Permalink
fix: wrong transformer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Mar 23, 2024
1 parent d1dae15 commit ce23fbc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ from date in clicksPerDay.Keys.Where(k => k.blogPostId == blogPost.Id)
foreach (var userRecord in userRecords)
{
var id = userRecord.UrlClicked.Replace("blogPost/", string.Empty, StringComparison.OrdinalIgnoreCase);
var suffix = id.IndexOf('/', StringComparison.InvariantCultureIgnoreCase);
if (suffix != -1)
{
id = id[..suffix];
}
var key = (id, userRecord.DateClicked);
clicksPerDay.TryGetValue(key, out var count);
clicksPerDay[key] = count + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task ShouldTransformRecords()
var userRecords = new List<UserRecord>
{
new() { Id = "A", DateClicked = someDate, UrlClicked = $"blogPost/{blogPosts[0].Id}" },
new() { Id = "B", DateClicked = someDate, UrlClicked = $"blogPost/{blogPosts[0].Id}" },
new() { Id = "B", DateClicked = someDate, UrlClicked = $"blogPost/{blogPosts[0].Id}/suffix" },
new() { Id = "C", DateClicked = someDate.AddDays(-3), UrlClicked = $"blogPost/{blogPosts[1].Id}" },
new() { Id = "D", DateClicked = someDate.AddDays(-3), UrlClicked = $"blogPost/{blogPosts[1].Id}" },
new() { Id = "E", DateClicked = someDate.AddDays(-2), UrlClicked = $"blogPost/{blogPosts[2].Id}" }
Expand Down

0 comments on commit ce23fbc

Please sign in to comment.