@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user