64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using Helpdesk.Domain.Issues;
|
|
using Helpdesk.Domain.Proposals;
|
|
|
|
namespace Helpdesk.Domain.Notifications;
|
|
|
|
public enum NotificationType { IssueCreated, IssueAssigned, IssueStatusChanged, IssueCommentAdded, IssueReopened, ProposalStatusChanged }
|
|
public enum DeliveryChannel { Email, Push }
|
|
public enum DeliveryStatus { Pending, Skipped }
|
|
|
|
public sealed class Notification : IHasCreatedAt
|
|
{
|
|
private Notification() { }
|
|
|
|
public Notification(Issue issue, int userId, NotificationType type, string title, string message)
|
|
: this(userId, type, title, message)
|
|
{
|
|
Issue = issue;
|
|
}
|
|
|
|
public Notification(Proposal proposal, int userId, string title)
|
|
: this(userId, NotificationType.ProposalStatusChanged, title, proposal.Title)
|
|
{
|
|
ProposalId = proposal.Id;
|
|
}
|
|
|
|
private Notification(int userId, NotificationType type, string title, string message)
|
|
{
|
|
UserId = userId;
|
|
Type = type;
|
|
Title = title;
|
|
Message = message;
|
|
}
|
|
|
|
public int Id { get; private set; }
|
|
public int? IssueId { get; private set; }
|
|
public int? ProposalId { get; private set; }
|
|
public Issue? Issue { get; private set; }
|
|
public int UserId { get; private set; }
|
|
public NotificationType Type { get; private set; }
|
|
public string Title { get; private set; } = null!;
|
|
public string Message { get; private set; } = null!;
|
|
public DateTime CreatedAt { get; set; }
|
|
public DateTime? ReadAt { get; private set; }
|
|
}
|
|
|
|
public sealed class NotificationDelivery(
|
|
Notification notification, DeliveryChannel channel, bool enabled, DateTime now)
|
|
{
|
|
private NotificationDelivery() : this(null!, default, false, default) { }
|
|
|
|
public int Id { get; private set; }
|
|
public int NotificationId { get; private set; }
|
|
public Notification Notification { get; private set; } = notification;
|
|
public DeliveryChannel Channel { get; private set; } = channel;
|
|
public DeliveryStatus Status { get; private set; } = enabled ? DeliveryStatus.Pending : DeliveryStatus.Skipped;
|
|
public DateTime? NextAttemptAt { get; private set; } = enabled ? now : null;
|
|
}
|
|
|
|
public sealed class PushDevice
|
|
{
|
|
public int Id { get; private set; }
|
|
public int UserId { get; private set; }
|
|
}
|