Improved Webhook logging

This commit is contained in:
Mia Rose Winter 2024-04-09 13:36:06 +02:00
parent 0a05cb5de7
commit 61e31ec2e1
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -13,7 +13,6 @@ public class WebhookController(ILogger<WebhookController> logger, ApplicationDbC
[HttpPost("mailtrap/{apiKey}")]
[Authorize("EmailApi", AuthenticationSchemes = "ApiKeyInRoute")]
public async Task<IActionResult> Mailtrap(Webhook webhook, string apiKey) {
Console.WriteLine(apiKey);
foreach (var webhookEvent in webhook.Events) {
var subscriber = await context.Set<EmailSubscriber>().FirstOrDefaultAsync(s => s.Email == webhookEvent.Email);
@ -52,6 +51,9 @@ public class WebhookController(ILogger<WebhookController> logger, ApplicationDbC
subscriber.Unsubscribed = true;
subscriber.UnsubscribeReason ??= webhookEvent.Reason?.Humanize().Titleize() ?? "Rejected";
break;
default:
logger.LogInformation("Received unsupported event {EventType}. Skipping.", webhookEvent.Type);
return Ok();
}
await context.SaveChangesAsync();