Skip to content

Commit

Permalink
Add analytics events (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bardin08 authored May 20, 2024
2 parents 934f6ec + 388b407 commit a090465
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Trumpee.MassTransit.Messages/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
[bB]in
[oO]bj
12 changes: 12 additions & 0 deletions Trumpee.MassTransit.Messages/Event.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Trumpee.MassTransit.Messages;

public class Event<TBody>
{
public TBody? Payload { get; set; }

public required string Id { get; set; }
public required string Action { get; set; }
public required string Source { get; set; }
public DateTimeOffset Timestamp { get; set; }
public Dictionary<string, string>? Metadata { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Trumpee.MassTransit.Messages.Notifications.Template;

public class TemplateFilledEvent : Event<TemplateFilledPayload>
{
public static TemplateFilledEvent GetEvent(
string source, string templateId, string notificationId)
{
return new TemplateFilledEvent
{
Id = Guid.NewGuid().ToString("N"),
Action = nameof(TemplateNotFilledEvent).ToLower(),
Source = source,
Timestamp = DateTimeOffset.UtcNow,
Metadata = [],
Payload = new TemplateFilledPayload
{
TemplateId = templateId,
NotificationId = notificationId
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Trumpee.MassTransit.Messages.Notifications.Template;

public class TemplateFilledPayload
{
public required string TemplateId { get; set; }
public required string NotificationId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Trumpee.MassTransit.Messages.Notifications.Template;

public class TemplateNotFilledEvent : Event<TemplateNotFilledPayload>
{
public static TemplateNotFilledEvent GetEvent(
string source, string templateId, string notificationId)
{
return new TemplateNotFilledEvent
{
Id = Guid.NewGuid().ToString("N"),
Action = nameof(TemplateNotFilledEvent).ToLower(),
Source = source,
Timestamp = DateTimeOffset.UtcNow,
Metadata = [],
Payload = new TemplateNotFilledPayload
{
TemplateId = templateId,
NotificationId = notificationId
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Trumpee.MassTransit.Messages.Notifications.Template;

public class TemplateNotFilledPayload
{
public required string TemplateId { get; set; }
public required string NotificationId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Trumpee.MassTransit.Messages.Notifications.Template;

public class TemplateNotFoundEvent : Event<TemplateNotFoundPayload>
{
public static TemplateNotFoundEvent GetEvent(string source, string templateId, Dictionary<string, string> props)
{
return new TemplateNotFoundEvent
{
Id = Guid.NewGuid().ToString("N"),
Action = nameof(TemplateNotFoundEvent).ToLower(),
Source = source,
Timestamp = DateTimeOffset.UtcNow,
Metadata = [],
Payload = new TemplateNotFoundPayload
{
TemplateId = templateId,
Properties = props
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Trumpee.MassTransit.Messages.Notifications.Template;

public class TemplateNotFoundPayload
{
public required string TemplateId { get; set; }
public Dictionary<string, string>? Properties { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Trumpee.MassTransit.Messages.Notifications.Validation;

public class ValidationFailedEvent : Event<ValidationFailedPayload>
{
public static ValidationFailedEvent GetEvent(string source, string notificationId, string error)
{
return new ValidationFailedEvent
{
Id = Guid.NewGuid().ToString("N"),
Action = nameof(ValidationFailedEvent).ToLower(),
Source = source,
Timestamp = DateTimeOffset.UtcNow,
Metadata = [],
Payload = new ValidationFailedPayload
{
NotificationId = notificationId,
ErrorMessage = error
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Trumpee.MassTransit.Messages.Notifications.Validation;

public class ValidationFailedPayload
{
public string? NotificationId { get; set; }
public string? ErrorMessage { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Trumpee.MassTransit.Messages.Notifications.Validation;

public class ValidationPassedEvent : Event<ValidationPassedPayload>
{
public static ValidationPassedEvent GetEvent(string source, string notificationId)
{
return new ValidationPassedEvent
{
Id = Guid.NewGuid().ToString("N"),
Action = nameof(ValidationFailedEvent).ToLower(),
Source = source,
Timestamp = DateTimeOffset.UtcNow,
Metadata = [],
Payload = new ValidationPassedPayload
{
NotificationId = notificationId
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Trumpee.MassTransit.Messages.Notifications.Validation;

public class ValidationPassedPayload
{
public string? NotificationId { get; set; }
}

0 comments on commit a090465

Please sign in to comment.