From 1672d460382abb78dc9f9add42549fee9502dd0c Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 6 Jul 2025 23:43:24 +0800 Subject: [PATCH] :rewind: Uncomments code that prevents errors when missing services --- .../Account/NotificationController.cs | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/DysonNetwork.Pass/Account/NotificationController.cs b/DysonNetwork.Pass/Account/NotificationController.cs index 279da4d..98eb8a8 100644 --- a/DysonNetwork.Pass/Account/NotificationController.cs +++ b/DysonNetwork.Pass/Account/NotificationController.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using DysonNetwork.Shared.Models; using DysonNetwork.Pass.Auth; +using DysonNetwork.Pass.Permission; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -49,7 +50,7 @@ public class NotificationController(AppDatabase db, NotificationService nty) : C .ToListAsync(); Response.Headers["X-Total"] = totalCount.ToString(); - // await nty.MarkNotificationsViewed(notifications); + await nty.MarkNotificationsViewed(notifications); return Ok(notifications); } @@ -73,9 +74,8 @@ public class NotificationController(AppDatabase db, NotificationService nty) : C var currentSession = currentSessionValue as Session; if (currentSession == null) return Unauthorized(); - // var result = - // await nty.SubscribePushNotification(currentUser, request.Provider, currentSession.Challenge.DeviceId!, - // request.DeviceToken); + await nty.SubscribePushNotification(currentUser, request.Provider, currentSession.Challenge.DeviceId!, + request.DeviceToken); return Ok(); } @@ -111,26 +111,26 @@ public class NotificationController(AppDatabase db, NotificationService nty) : C [HttpPost("broadcast")] [Authorize] - // [RequiredPermission("global", "notifications.broadcast")] + [RequiredPermission("global", "notifications.broadcast")] public async Task BroadcastNotification( [FromBody] NotificationRequest request, [FromQuery] bool save = false ) { - // await nty.BroadcastNotification( - // new Notification - // { - // CreatedAt = SystemClock.Instance.GetCurrentInstant(), - // UpdatedAt = SystemClock.Instance.GetCurrentInstant(), - // Topic = request.Topic, - // Title = request.Title, - // Subtitle = request.Subtitle, - // Content = request.Content, - // Meta = request.Meta, - // Priority = request.Priority, - // }, - // save - // ); + await nty.BroadcastNotification( + new Notification + { + CreatedAt = SystemClock.Instance.GetCurrentInstant(), + UpdatedAt = SystemClock.Instance.GetCurrentInstant(), + Topic = request.Topic, + Title = request.Title, + Subtitle = request.Subtitle, + Content = request.Content, + Meta = request.Meta, + Priority = request.Priority, + }, + save + ); return Ok(); } @@ -141,27 +141,27 @@ public class NotificationController(AppDatabase db, NotificationService nty) : C [HttpPost("send")] [Authorize] - // [RequiredPermission("global", "notifications.send")] + [RequiredPermission("global", "notifications.send")] public async Task SendNotification( [FromBody] NotificationWithAimRequest request, [FromQuery] bool save = false ) { var accounts = await db.Accounts.Where(a => request.AccountId.Contains(a.Id)).ToListAsync(); - // await nty.SendNotificationBatch( - // new Notification - // { - // CreatedAt = SystemClock.Instance.GetCurrentInstant(), - // UpdatedAt = SystemClock.Instance.GetCurrentInstant(), - // Topic = request.Topic, - // Title = request.Title, - // Subtitle = request.Subtitle, - // Content = request.Content, - // Meta = request.Meta, - // }, - // accounts, - // save - // ); + await nty.SendNotificationBatch( + new Notification + { + CreatedAt = SystemClock.Instance.GetCurrentInstant(), + UpdatedAt = SystemClock.Instance.GetCurrentInstant(), + Topic = request.Topic, + Title = request.Title, + Subtitle = request.Subtitle, + Content = request.Content, + Meta = request.Meta, + }, + accounts, + save + ); return Ok(); } } \ No newline at end of file