-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to receive and save email open notifications.
- Loading branch information
n.bitounis
committed
May 11, 2020
1 parent
35a11ec
commit 5de543a
Showing
14 changed files
with
300 additions
and
19 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
Projects/SesNotifications.App/Factories/DbSesOpenFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using SesNotifications.App.Models; | ||
using SesOpen = SesNotifications.DataAccess.Entities.SesOpen; | ||
|
||
namespace SesNotifications.App.Factories | ||
{ | ||
public static class DbSesOpenFactory | ||
{ | ||
public static SesOpen Create(this SesOpenModel open, long notificationId) | ||
{ | ||
return new SesOpen | ||
{ | ||
Id = notificationId, | ||
NotificationId = notificationId, | ||
NotificationType = "Open", | ||
SentAt = Convert.ToDateTime(open.Mail.Timestamp), | ||
MessageId = open.Mail.MessageId, | ||
Source = open.Mail.Source, | ||
SourceArn = open.Mail.SourceArn, | ||
SourceIp = open.Mail.SourceIp, | ||
SendingAccountId = open.Mail.SendingAccountId, | ||
Recipients = string.Join(',', open.Mail.Destination), | ||
OpenedAt = Convert.ToDateTime(open.Open.Timestamp), | ||
UserAgent = open.Open.UserAgent, | ||
IpAddress = open.Open.IpAddress | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SesNotifications.App.Models | ||
{ | ||
public class SesOpen | ||
{ | ||
public virtual string Timestamp { get; set; } | ||
public virtual string UserAgent { get; set; } | ||
public virtual string IpAddress { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SesNotifications.App.Models | ||
{ | ||
public class SesOpenModel : Ses | ||
{ | ||
public virtual SesMail Mail { get; set; } | ||
public virtual SesOpen Open { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace SesNotifications.DataAccess.Entities | ||
{ | ||
public class SesOpen : SesCommon | ||
{ | ||
public virtual string Recipients { get; set; } | ||
public virtual DateTime OpenedAt { get; set; } | ||
public virtual string UserAgent { get; set; } | ||
public virtual string IpAddress { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Projects/SesNotifications.DataAccess/Mappings/SesOpenMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using SesNotifications.DataAccess.Entities; | ||
|
||
namespace SesNotifications.DataAccess.Mappings | ||
{ | ||
public class SesOpenMap : SesCommonMap<SesOpen> | ||
{ | ||
public SesOpenMap() | ||
{ | ||
Table("ses_notifications.opens"); | ||
MapCommon(); | ||
Map(x => x.Recipients).Column("recipients"); | ||
Map(x => x.OpenedAt).Column("opened_at"); | ||
Map(x => x.UserAgent).Column("user_agent"); | ||
Map(x => x.IpAddress).Column("ip_address"); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Projects/SesNotifications.DataAccess/Repositories/Interfaces/ISesOpensRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using SesNotifications.DataAccess.Entities; | ||
|
||
namespace SesNotifications.DataAccess.Repositories.Interfaces | ||
{ | ||
public interface ISesOpensRepository | ||
{ | ||
void Save(SesOpen sesOpen); | ||
SesOpen FindById(long id); | ||
IList<SesOpen> FindByMessageId(string messageId); | ||
IList<SesOpen> FindBySentDateRange(DateTime start, DateTime end); | ||
IList<SesOpen> FindByRecipient(string email); | ||
IList<SesOpen> FindByRecipientAndSentDateRange(string email, DateTime start, DateTime end); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
Projects/SesNotifications.DataAccess/Repositories/SesOpensRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using NHibernate; | ||
using NHibernate.Criterion; | ||
using SesNotifications.DataAccess.Entities; | ||
using SesNotifications.DataAccess.Repositories.Interfaces; | ||
|
||
namespace SesNotifications.DataAccess.Repositories | ||
{ | ||
public class SesOpensRepository : Repository, ISesOpensRepository | ||
{ | ||
|
||
public SesOpensRepository() | ||
{ | ||
} | ||
|
||
public SesOpensRepository(ISession session) : base(session) | ||
{ | ||
} | ||
|
||
public void Save(SesOpen sesDelivery) | ||
{ | ||
Session.Save(sesDelivery); | ||
} | ||
|
||
public SesOpen FindById(long id) | ||
{ | ||
return Session.Get<SesOpen>(id); | ||
} | ||
|
||
public IList<SesOpen> FindByMessageId(string messageId) | ||
{ | ||
return Session.CreateCriteria<SesOpen>() | ||
.Add(Restrictions.Eq(nameof(SesOpen.MessageId), messageId)) | ||
.List<SesOpen>(); | ||
} | ||
|
||
public IList<SesOpen> FindBySentDateRange(DateTime start, DateTime end) | ||
{ | ||
return Session.CreateCriteria<SesOpen>() | ||
.Add(Restrictions.Ge(nameof(SesOpen.SentAt), start)) | ||
.Add(Restrictions.Le(nameof(SesOpen.SentAt), end)) | ||
.AddOrder(Order.Desc(nameof(SesOpen.SentAt))) | ||
.List<SesOpen>(); | ||
} | ||
|
||
public IList<SesOpen> FindByRecipient(string email) | ||
{ | ||
return Session.CreateCriteria<SesOpen>() | ||
.Add(Restrictions.InsensitiveLike(nameof(SesOpen.Recipients), email)) | ||
.AddOrder(Order.Desc(nameof(SesOpen.SentAt))) | ||
.List<SesOpen>(); | ||
} | ||
|
||
public IList<SesOpen> FindByRecipientAndSentDateRange(string email, DateTime start, DateTime end) | ||
{ | ||
return Session.CreateCriteria<SesOpen>() | ||
.Add(Restrictions.InsensitiveLike(nameof(SesOpen.Recipients), email)) | ||
.Add(Restrictions.Ge(nameof(SesOpen.SentAt), start)) | ||
.Add(Restrictions.Le(nameof(SesOpen.SentAt), end)) | ||
.AddOrder(Order.Desc(nameof(SesOpen.SentAt))) | ||
.List<SesOpen>(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Tests/SesNotifications.App.Tests/Factories/DbSesOpenFactoryTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using SesNotifications.App.Factories; | ||
using SesNotifications.App.Tests.Helpers; | ||
using Xunit; | ||
|
||
namespace SesNotifications.App.Tests.Factories | ||
{ | ||
public class DbSesOpenFactoryTests | ||
{ | ||
[Fact] | ||
public void Verify() | ||
{ | ||
var dt = DateTime.UtcNow; | ||
var open = TestHelpers.GetSesOpenModel(dt); | ||
|
||
var sesOpen = open.Create(1); | ||
|
||
Assert.Equal(sesOpen.Recipients, string.Join(',', open.Mail.Destination)); | ||
Assert.Equal(sesOpen.OpenedAt.Iso8601(), open.Open.Timestamp); | ||
Assert.Equal(sesOpen.SourceArn, open.Mail.SourceArn); | ||
Assert.Equal(sesOpen.NotificationType, open.NotificationType); | ||
Assert.Equal(1, sesOpen.NotificationId); | ||
Assert.Equal(sesOpen.MessageId, open.Mail.MessageId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.