Migliorata gestione e visualizzazione notifiche

This commit is contained in:
2025-09-12 15:42:56 +02:00
parent b798b01da0
commit 223e74c490
20 changed files with 229 additions and 60 deletions

View File

@@ -0,0 +1,45 @@
using salesbook.Shared.Core.Dto.PageState;
using salesbook.Shared.Core.Interface;
using salesbook.Shared.Core.Interface.IntegryApi;
namespace salesbook.Shared.Core.Services;
public class NotificationService(
IIntegryNotificationRestClient integryNotificationRestClient,
NotificationState Notification
) : INotificationService
{
public async Task LoadNotification()
{
var allNotifications = await integryNotificationRestClient.Get();
var allIds = allNotifications.Select(n => n.Id).ToHashSet();
Notification.ReceivedNotifications = Notification.ReceivedNotifications
.Where(r => !allIds.Contains(r.Id))
.ToList();
Notification.UnreadNotifications = allNotifications
.Where(x =>
x.WtbDeviceNotifications == null ||
x.WtbDeviceNotifications.Any(y => y.ReadDate == null))
.ToList();
Notification.NotificationsRead = allNotifications
.Where(x =>
x.WtbDeviceNotifications != null &&
x.WtbDeviceNotifications.All(y => y.ReadDate != null))
.ToList();
}
public void OrderNotificationList()
{
Notification.ReceivedNotifications = Notification.ReceivedNotifications
.OrderByDescending(x => x.StartDate).ToList();
Notification.UnreadNotifications = Notification.UnreadNotifications
.OrderByDescending(x => x.StartDate).ToList();
Notification.NotificationsRead = Notification.NotificationsRead
.OrderByDescending(x => x.StartDate).ToList();
}
}