✨ Mark all notifications read
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using DysonNetwork.Shared.Data;
|
using DysonNetwork.Shared.Data;
|
||||||
using DysonNetwork.Shared.Proto;
|
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
|
|
||||||
namespace DysonNetwork.Pusher.Notification;
|
namespace DysonNetwork.Pusher.Notification;
|
||||||
|
@@ -5,7 +5,6 @@ using Microsoft.AspNetCore.Authorization;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
using AccountService = DysonNetwork.Shared.Proto.AccountService;
|
|
||||||
|
|
||||||
namespace DysonNetwork.Pusher.Notification;
|
namespace DysonNetwork.Pusher.Notification;
|
||||||
|
|
||||||
@@ -13,8 +12,8 @@ namespace DysonNetwork.Pusher.Notification;
|
|||||||
[Route("/api/notifications")]
|
[Route("/api/notifications")]
|
||||||
public class NotificationController(
|
public class NotificationController(
|
||||||
AppDatabase db,
|
AppDatabase db,
|
||||||
PushService nty,
|
PushService nty
|
||||||
AccountService.AccountServiceClient accounts) : ControllerBase
|
) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet("count")]
|
[HttpGet("count")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
@@ -59,6 +58,18 @@ public class NotificationController(
|
|||||||
return Ok(notifications);
|
return Ok(notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("all/read")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<ActionResult> MarkAllNotificationsViewed()
|
||||||
|
{
|
||||||
|
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||||
|
if (currentUserValue is not Account currentUser) return Unauthorized();
|
||||||
|
var accountId = Guid.Parse(currentUser.Id);
|
||||||
|
|
||||||
|
await nty.MarkAllNotificationsViewed(accountId);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
public class PushNotificationSubscribeRequest
|
public class PushNotificationSubscribeRequest
|
||||||
{
|
{
|
||||||
[MaxLength(4096)] public string DeviceToken { get; set; } = null!;
|
[MaxLength(4096)] public string DeviceToken { get; set; } = null!;
|
||||||
|
@@ -173,6 +173,14 @@ public class PushService
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task MarkAllNotificationsViewed(Guid accountId)
|
||||||
|
{
|
||||||
|
var now = SystemClock.Instance.GetCurrentInstant();
|
||||||
|
await _db.Notifications
|
||||||
|
.Where(n => n.AccountId == accountId)
|
||||||
|
.ExecuteUpdateAsync(s => s.SetProperty(n => n.ViewedAt, now));
|
||||||
|
}
|
||||||
|
|
||||||
public async Task SendNotificationBatch(Notification notification, List<Guid> accounts, bool save = false)
|
public async Task SendNotificationBatch(Notification notification, List<Guid> accounts, bool save = false)
|
||||||
{
|
{
|
||||||
if (save)
|
if (save)
|
||||||
|
Reference in New Issue
Block a user