28 lines
824 B
C#
28 lines
824 B
C#
|
|
namespace WebApi.Controllers;
|
|||
|
|
|
|||
|
|
[ApiController]
|
|||
|
|
[Route("api/[controller]")]
|
|||
|
|
public class NotificationController(INotificationService notificationService) : ControllerBase
|
|||
|
|
{
|
|||
|
|
[HttpGet("vapid-public-key")]
|
|||
|
|
public async Task<IActionResult> GetVapidPublicKey()
|
|||
|
|
{
|
|||
|
|
var key = await notificationService.GetVapidPublicKeyAsync();
|
|||
|
|
return Ok(new { publicKey = key });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpPost("subscribe")]
|
|||
|
|
public async Task<IActionResult> Subscribe([FromBody] PushSubscriptionEntity subscription)
|
|||
|
|
{
|
|||
|
|
await notificationService.SubscribeAsync(subscription);
|
|||
|
|
return Ok();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[HttpPost("test")]
|
|||
|
|
public async Task<IActionResult> TestNotification([FromQuery] string message)
|
|||
|
|
{
|
|||
|
|
await notificationService.SendNotificationAsync(message);
|
|||
|
|
return Ok();
|
|||
|
|
}
|
|||
|
|
}
|