Files
EmailBill/WebApi/Controllers/NotificationController.cs
孙诚 36126097fa
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 21s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 0s
重命名 PushSubscriptionEntity 为 PushSubscription,并更新相关引用
2026-01-04 16:59:34 +08:00

47 lines
1.1 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 key.Ok<string>();
}
catch (Exception ex)
{
return ex.Message.Fail<string>();
}
}
public async Task<BaseResponse> Subscribe([FromBody] PushSubscription subscription)
{
try
{
await notificationService.SubscribeAsync(subscription);
return BaseResponse.Done();
}
catch (Exception ex)
{
return ex.Message.Fail();
}
}
public async Task<BaseResponse> TestNotification([FromQuery] string message)
{
try
{
await notificationService.SendNotificationAsync(message);
return BaseResponse.Done();
}
catch (Exception ex)
{
return ex.Message.Fail();
}
}
}