47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
namespace WebApi.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]/[action]")]
|
|
public class NotificationController(INotificationService notificationService) : ControllerBase
|
|
{
|
|
[HttpGet()]
|
|
public async Task<BaseResponse<string>> GetVapidPublicKey()
|
|
{
|
|
try
|
|
{
|
|
var key = await notificationService.GetVapidPublicKeyAsync();
|
|
return BaseResponse<string>.Done(key);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BaseResponse<string>.Fail(ex.Message);
|
|
}
|
|
}
|
|
|
|
public async Task<BaseResponse> Subscribe([FromBody] PushSubscriptionEntity subscription)
|
|
{
|
|
try
|
|
{
|
|
await notificationService.SubscribeAsync(subscription);
|
|
return BaseResponse.Done();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BaseResponse.Fail(ex.Message);
|
|
}
|
|
}
|
|
|
|
public async Task<BaseResponse> TestNotification([FromQuery] string message)
|
|
{
|
|
try
|
|
{
|
|
await notificationService.SendNotificationAsync(message);
|
|
return BaseResponse.Done();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return BaseResponse.Fail(ex.Message);
|
|
}
|
|
}
|
|
}
|