Skip to content

Commit

Permalink
* Added delivery events and UI.
Browse files Browse the repository at this point in the history
* Various renames and fixes.
  • Loading branch information
n.bitounis committed Jun 1, 2020
1 parent 1bf57ad commit d111fd3
Show file tree
Hide file tree
Showing 35 changed files with 558 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using SesNotifications.App.Models;
using SesDeliveryEvent = SesNotifications.DataAccess.Entities.SesDeliveryEvent;

namespace SesNotifications.App.Factories
{
public static class DbSesDeliveryEventFactory
{
public static SesDeliveryEvent Create(this SesDeliveryEventModel delivery, long notificationId)
{
return new SesDeliveryEvent
{
NotificationId = notificationId,
NotificationType = "Delivery",
SentAt = Convert.ToDateTime(delivery.Mail.Timestamp),
MessageId = delivery.Mail.MessageId,
Source = delivery.Mail.Source,
SourceArn = delivery.Mail.SourceArn,
SourceIp = delivery.Mail.SourceIp,
SendingAccountId = delivery.Mail.SendingAccountId,
DeliveredAt = Convert.ToDateTime(delivery.Delivery.Timestamp),
SmtpResponse = delivery.Delivery.SmtpResponse,
ReportingMta = delivery.Delivery.ReportingMta,
Recipients = string.Join(',', delivery.Delivery.Recipients)
};
}
}
}
30 changes: 30 additions & 0 deletions Projects/SesNotifications.App/Factories/DbSesOpenEventFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using SesNotifications.App.Models;
using SesNotifications.DataAccess.Entities;
using SesOpenEvent = SesNotifications.DataAccess.Entities.SesOpenEvent;

namespace SesNotifications.App.Factories
{
public static class DbSesOpenEventFactory
{
public static SesOpenEvent Create(this SesOpenEventModel openEvent, long notificationId)
{
return new SesOpenEvent
{
Id = notificationId,
NotificationId = notificationId,
NotificationType = "Open",
SentAt = Convert.ToDateTime(openEvent.Mail.Timestamp),
MessageId = openEvent.Mail.MessageId,
Source = openEvent.Mail.Source,
SourceArn = openEvent.Mail.SourceArn,
SourceIp = openEvent.Mail.SourceIp,
SendingAccountId = openEvent.Mail.SendingAccountId,
Recipients = string.Join(',', openEvent.Mail.Destination),
OpenedAt = Convert.ToDateTime(openEvent.Open.Timestamp),
UserAgent = openEvent.Open.UserAgent,
IpAddress = openEvent.Open.IpAddress
};
}
}
}
29 changes: 0 additions & 29 deletions Projects/SesNotifications.App/Factories/DbSesOpenFactory.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System;
using SesNotifications.App.Models;
using SesNotifications.DataAccess.Entities;
using SesSendEvent = SesNotifications.DataAccess.Entities.SesSendEvent;

namespace SesNotifications.App.Factories
{
public static class DbSesSendFactory
public static class DbSesSendEventFactory
{
public static SesSendEvent Create(this SesSendModel open, long notificationId)
public static SesSendEvent Create(this SesSendEventModel open, long notificationId)
{
return new SesSendEvent
{
Expand Down
10 changes: 10 additions & 0 deletions Projects/SesNotifications.App/Models/SesDeliveryEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SesNotifications.App.Models
{
public class SesDeliveryEvent
{
public virtual string Timestamp { get; set; }
public virtual string[] Recipients { get; set; }
public virtual string SmtpResponse { get; set; }
public virtual string ReportingMta { get; set; }
}
}
8 changes: 8 additions & 0 deletions Projects/SesNotifications.App/Models/SesDeliveryEventModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SesNotifications.App.Models
{
public class SesDeliveryEventModel : Ses
{
public virtual SesMail Mail { get; set; }
public virtual SesDeliveryEvent Delivery { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SesNotifications.App.Models
{
public class SesOpen
public class SesOpenEvent
{
public virtual string Timestamp { get; set; }
public virtual string UserAgent { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace SesNotifications.App.Models
{
public class SesSendModel : Ses
public class SesOpenEventModel : Ses
{
public virtual SesMail Mail { get; set; }
public virtual SesSend Send { get; set; }
public virtual SesOpenEvent Open { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SesNotifications.App.Models
{
public class SesSend
public class SesSendEvent
{
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace SesNotifications.App.Models
{
public class SesOpenModel : Ses
public class SesSendEventModel : Ses
{
public virtual SesMail Mail { get; set; }
public virtual SesOpen Open { get; set; }
public virtual SesSendEvent Send { get; set; }
}
}
74 changes: 74 additions & 0 deletions Projects/SesNotifications.App/Pages/FindDeliveryEvents.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@page
@model SesNotifications.App.Pages.FindDeliveryEventsModel
@{
ViewData["Title"] = "Find delivery events";
}

<!DOCTYPE html>

<h1>@ViewData["Title"]</h1>
<h4>Search for delivery events by date range and optional recipient.</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label>Starting date</label>
<input asp-for="Input.Start" class="form-control" />
<span asp-validation-for="Input.Start" class="text-danger"></span>

<label>Ending date</label>
<input asp-for="Input.End" class="form-control" />
<span asp-validation-for="Input.End" class="text-danger"></span>

<label asp-for="Input.Email"></label>
<input asp-for="Input.Email" class="form-control" />
<span asp-validation-for="Input.Email" class="text-danger"></span>
</div>

<button type="submit" class="btn btn-primary">Submit</button>
</form>
<br />

<table class="table">
<tr>
<th>ID</th>
<th>Notification ID</th>
<th>Notification Type</th>
<th>Sent at</th>
<th>Message ID</th>
<th>Source</th>
<th>Recipients</th>
<th>Source ARN</th>
<th>Source IP</th>
<th>Sending Account ID</th>
<th>Delivered At</th>
<th>SMTP Response</th>
<th>Reporting MTA</th>
<th>Raw model</th>
<th>Raw message</th>
</tr>
@foreach (var record in Model.DeliveryEvents)
{
<tr>
<td>@record.Id</td>
<td>@record.NotificationId</td>
<td>@record.NotificationType</td>
<td>@record.SentAt.ToString("yyyy-MM-dd HH:mm:ssZ")</td>
<td>@record.MessageId</td>
<td>@record.Source</td>
<td>@record.Recipients</td>
<td>@record.SourceArn</td>
<td>@record.SourceIp</td>
<td>@record.SendingAccountId</td>
<td>@record.DeliveredAt.ToString("yyyy-MM-dd HH:mm:ssZ")</td>
<td>@record.SmtpResponse</td>
<td>@record.ReportingMta</td>
<td><a target="_blank" href="@Url.Action("FindRawById", "Searches", new {id = record.NotificationId})">RAW (MODEL)</a></td>
<td><a target="_blank" href="@string.Concat(Url.Action("FindMessageById", "Searches", new {id = record.NotificationId}), "/text")">RAW (MESSAGE)</a></td>
</tr>
}
</table>
</div>
</div>
44 changes: 44 additions & 0 deletions Projects/SesNotifications.App/Pages/FindDeliveryEvents.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using SesNotifications.App.Services.Interfaces;
using SesNotifications.DataAccess.Entities;

namespace SesNotifications.App.Pages
{
public class FindDeliveryEventsModel : PageModel
{
[BindProperty]
public InputModel Input { get; set; }

public IList<SesDeliveryEvent> DeliveryEvents { get; set; } = new List<SesDeliveryEvent>();

public class InputModel
{
[Required]
[DataType(DataType.Date)]
public DateTime Start { get; set; }

[Required]
[DataType(DataType.Date)]
public DateTime End { get; set; }

public string Email { get; set; }
}

private readonly ISearchService _searchService;

public FindDeliveryEventsModel(ISearchService searchService)
{
_searchService = searchService;
}

public IActionResult OnPost()
{
DeliveryEvents = _searchService.FindDeliveryEvents(Input.Email, Input.Start, Input.End);
return Page();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@page
@model SesNotifications.App.Pages.FindOpensModel
@model SesNotifications.App.Pages.FindOpenEventsModel
@{
ViewData["Title"] = "Find opens";
ViewData["Title"] = "Find open events";
}

<!DOCTYPE html>

<h1>@ViewData["Title"]</h1>
<h4>Search for opens by date range and optional recipient.</h4>
<h4>Search for open events by date range and optional recipient.</h4>
<hr />
<div class="row">
<div class="col-md-4">
Expand Down Expand Up @@ -49,7 +49,7 @@
<th>User Agent</th>
<th>IP Address</th>
</tr>
@foreach (var record in Model.Opens)
@foreach (var record in Model.OpenEvents)
{
<tr>
<td>@record.Id</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

namespace SesNotifications.App.Pages
{
public class FindOpensModel : PageModel
public class FindOpenEventsModel : PageModel
{
[BindProperty]
public InputModel Input { get; set; }

public IList<SesOpenEvent> Opens { get; set; } = new List<SesOpenEvent>();
public IList<SesOpenEvent> OpenEvents { get; set; } = new List<SesOpenEvent>();

public class InputModel
{
Expand All @@ -30,14 +30,14 @@ public class InputModel

private readonly ISearchService _searchService;

public FindOpensModel(ISearchService searchService)
public FindOpenEventsModel(ISearchService searchService)
{
_searchService = searchService;
}

public IActionResult OnPost()
{
Opens = _searchService.FindOpens(Input.Email, Input.Start, Input.End);
OpenEvents = _searchService.FindOpenEvents(Input.Email, Input.Start, Input.End);
return Page();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@page
@model SesNotifications.App.Pages.FindSendsModel
@model SesNotifications.App.Pages.FindSendEventsModel
@{
ViewData["Title"] = "Find sends";
ViewData["Title"] = "Find send events";
}

<!DOCTYPE html>

<h1>@ViewData["Title"]</h1>
<h4>Search for sends by date range and optional recipient.</h4>
<h4>Search for send events by date range and optional recipient.</h4>
<hr />
<div class="row">
<div class="col-md-4">
Expand Down Expand Up @@ -46,7 +46,7 @@
<th>FeedbackId</th>
<th>Reporting MTA</th>
</tr>
@foreach (var record in Model.Sends)
@foreach (var record in Model.SendEvents)
{
<tr>
<td>@record.Id</td>
Expand Down
Loading

0 comments on commit d111fd3

Please sign in to comment.