mirror of
https://github.com/C9Glax/tranga.git
synced 2025-07-04 09:54:16 +02:00
SendNotificationsWorker.cs
This commit is contained in:
@ -19,6 +19,8 @@ public class Notification : Identifiable
|
|||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime Date { get; init; }
|
public DateTime Date { get; init; }
|
||||||
|
|
||||||
|
public bool IsSent { get; internal set; }
|
||||||
|
|
||||||
public Notification(string title, string message = "", NotificationUrgency urgency = NotificationUrgency.Normal, DateTime? date = null)
|
public Notification(string title, string message = "", NotificationUrgency urgency = NotificationUrgency.Normal, DateTime? date = null)
|
||||||
: base(TokenGen.CreateToken("Notification"))
|
: base(TokenGen.CreateToken("Notification"))
|
||||||
@ -27,18 +29,20 @@ public class Notification : Identifiable
|
|||||||
this.Message = message;
|
this.Message = message;
|
||||||
this.Urgency = urgency;
|
this.Urgency = urgency;
|
||||||
this.Date = date ?? DateTime.UtcNow;
|
this.Date = date ?? DateTime.UtcNow;
|
||||||
|
this.IsSent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// EF ONLY!!!
|
/// EF ONLY!!!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Notification(string key, string title, string message, NotificationUrgency urgency, DateTime date)
|
public Notification(string key, string title, string message, NotificationUrgency urgency, DateTime date, bool isSent)
|
||||||
: base(key)
|
: base(key)
|
||||||
{
|
{
|
||||||
this.Title = title;
|
this.Title = title;
|
||||||
this.Message = message;
|
this.Message = message;
|
||||||
this.Urgency = urgency;
|
this.Urgency = urgency;
|
||||||
this.Date = date;
|
this.Date = date;
|
||||||
|
this.IsSent = isSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString() => $"{base.ToString()} {Urgency} {Title}";
|
public override string ToString() => $"{base.ToString()} {Urgency} {Title}";
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using API.Schema.NotificationsContext;
|
using API.Schema.NotificationsContext;
|
||||||
|
using API.Schema.NotificationsContext.NotificationConnectors;
|
||||||
|
|
||||||
namespace API.Workers;
|
namespace API.Workers;
|
||||||
|
|
||||||
@ -9,7 +10,20 @@ public class SendNotificationsWorker(IEnumerable<BaseWorker>? dependsOn = null)
|
|||||||
public TimeSpan Interval { get; set; } = TimeSpan.FromMinutes(1);
|
public TimeSpan Interval { get; set; } = TimeSpan.FromMinutes(1);
|
||||||
protected override BaseWorker[] DoWorkInternal()
|
protected override BaseWorker[] DoWorkInternal()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
NotificationConnector[] connectors = DbContext.NotificationConnectors.ToArray();
|
||||||
|
Notification[] notifications = DbContext.Notifications.Where(n => n.IsSent == false).ToArray();
|
||||||
|
|
||||||
|
foreach (Notification notification in notifications)
|
||||||
|
{
|
||||||
|
foreach (NotificationConnector connector in connectors)
|
||||||
|
{
|
||||||
|
connector.SendNotification(notification.Title, notification.Message);
|
||||||
|
notification.IsSent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DbContext.Sync();
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user