| | | 1 | | namespace Estud.Back.Domain.Webhooks; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Chamada de Webhook |
| | | 5 | | /// </summary> |
| | | 6 | | public class WebhookCall |
| | | 7 | | { |
| | 46 | 8 | | public int Id { get; set; } |
| | 36 | 9 | | public int InstitutionId { get; set; } |
| | 36 | 10 | | public int WebhookSubscriptionId { get; set; } |
| | 36 | 11 | | public string Payload { get; set; } |
| | 28 | 12 | | public WebhookEventType EventType { get; set; } |
| | 52 | 13 | | public WebhookCallStatus Status { get; set; } |
| | 50 | 14 | | public int AttemptsCount { get; set; } |
| | 28 | 15 | | public DateTime CreatedAt { get; set; } |
| | 24 | 16 | | public List<WebhookCallAttempt> Attempts { get; set; } |
| | | 17 | | |
| | 104 | 18 | | private WebhookCall() { } |
| | | 19 | | |
| | 18 | 20 | | public WebhookCall( |
| | 18 | 21 | | int institutionId, |
| | 18 | 22 | | int webhookSubscriptionId, |
| | 18 | 23 | | object data, |
| | 18 | 24 | | WebhookEventType eventType) |
| | | 25 | | { |
| | 18 | 26 | | InstitutionId = institutionId; |
| | 18 | 27 | | WebhookSubscriptionId = webhookSubscriptionId; |
| | 18 | 28 | | Payload = (new { EventType = eventType, Data = data }).Serialize(); |
| | 18 | 29 | | EventType = eventType; |
| | 18 | 30 | | CreatedAt = DateTime.UtcNow; |
| | 18 | 31 | | Status = WebhookCallStatus.Pending; |
| | 18 | 32 | | } |
| | | 33 | | |
| | | 34 | | public void Success(int statusCode, string response) |
| | | 35 | | { |
| | 16 | 36 | | AttemptsCount++; |
| | 16 | 37 | | Status = WebhookCallStatus.Success; |
| | 16 | 38 | | Attempts.Add(new WebhookCallAttempt(Id, WebhookCallAttemptStatus.Success, statusCode, response)); |
| | 16 | 39 | | } |
| | | 40 | | |
| | | 41 | | public void Failed(int statusCode, string response) |
| | | 42 | | { |
| | 2 | 43 | | Status = WebhookCallStatus.Error; |
| | 2 | 44 | | Attempts.Add(new WebhookCallAttempt(Id, WebhookCallAttemptStatus.Error, statusCode, response)); |
| | | 45 | | |
| | 2 | 46 | | AttemptsCount++; |
| | 2 | 47 | | } |
| | | 48 | | } |