support PWA notification.
ci-cd-vm / ci-cd (push) Failing after 1m34s

This commit is contained in:
Chris Chen
2026-06-29 22:20:15 -07:00
parent 45d910b554
commit b9210f2501
32 changed files with 1054 additions and 12 deletions
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using ROLAC.API.Authorization;
using ROLAC.API.Data;
using ROLAC.API.DTOs.Notifications;
using ROLAC.API.Services.Logging;
@@ -20,15 +21,17 @@ public sealed class NotificationsController : ControllerBase
{
private readonly IEmailService _email;
private readonly ILineNotificationService _line;
private readonly IWebPushService _webPush;
private readonly AppDbContext _db;
private readonly CurrentUserAccessor _currentUser;
public NotificationsController(
IEmailService email, ILineNotificationService line,
IEmailService email, ILineNotificationService line, IWebPushService webPush,
AppDbContext db, CurrentUserAccessor currentUser)
{
_email = email;
_line = line;
_webPush = webPush;
_db = db;
_currentUser = currentUser;
}
@@ -92,4 +95,14 @@ public sealed class NotificationsController : ControllerBase
HtmlBody: request.HtmlBody,
Attachments: null,
SentByUserId: _currentUser.UserIdOrSystem), ct));
// Manual one-to-(few) Web Push send. Guarded by Settings:Write (sending is an admin capability);
// the Member Management "send push" test action calls this for a single member.
[HttpPost("send-webpush")]
[HasPermission(Modules.Settings, PermissionActions.Write)]
public async Task<IActionResult> SendWebPush([FromBody] SendWebPushRequest request, CancellationToken ct)
=> Ok(await _webPush.SendToMembersAsync(
request.MemberIds ?? [],
new WebPushPayload(request.Title, request.Body, request.Url),
_currentUser.UserIdOrSystem, ct));
}