Files
EmailBill/WebApi/Controllers/NotificationController.cs

49 lines
1.2 KiB
C#
Raw Normal View History

using Service.Message;
namespace WebApi.Controllers;
[ApiController]
2026-01-02 18:51:28 +08:00
[Route("api/[controller]/[action]")]
public class NotificationController(INotificationService notificationService) : ControllerBase
{
2026-01-18 22:04:56 +08:00
[HttpGet]
2026-01-02 18:51:28 +08:00
public async Task<BaseResponse<string>> GetVapidPublicKey()
{
2026-01-02 18:51:28 +08:00
try
{
var key = await notificationService.GetVapidPublicKeyAsync();
2026-01-04 16:43:32 +08:00
return key.Ok<string>();
2026-01-02 18:51:28 +08:00
}
catch (Exception ex)
{
2026-01-04 16:43:32 +08:00
return ex.Message.Fail<string>();
2026-01-02 18:51:28 +08:00
}
}
public async Task<BaseResponse> Subscribe([FromBody] PushSubscription subscription)
{
2026-01-02 18:51:28 +08:00
try
{
await notificationService.SubscribeAsync(subscription);
return BaseResponse.Done();
}
catch (Exception ex)
{
2026-01-04 16:43:32 +08:00
return ex.Message.Fail();
2026-01-02 18:51:28 +08:00
}
}
2026-01-30 10:41:19 +08:00
2026-01-02 18:51:28 +08:00
public async Task<BaseResponse> TestNotification([FromQuery] string message)
{
2026-01-02 18:51:28 +08:00
try
{
await notificationService.SendNotificationAsync(message);
return BaseResponse.Done();
}
catch (Exception ex)
{
2026-01-04 16:43:32 +08:00
return ex.Message.Fail();
2026-01-02 18:51:28 +08:00
}
}
}