| | 1 | | using Syki.Back.Features.Academic.CallWebhooks; |
| | 2 | |
|
| | 3 | | namespace Syki.Back.Features.Academic.CreateWebhookSubscription; |
| | 4 | |
|
| | 5 | | /// <summary> |
| | 6 | | /// Inscrição de Webhook para receber notificações sobre eventos acadêmicos. |
| | 7 | | /// </summary> |
| | 8 | | public class WebhookSubscription |
| | 9 | | { |
| 6 | 10 | | public Guid Id { get; set; } |
| 2 | 11 | | public Guid InstitutionId { get; set; } |
| 4 | 12 | | public string Name { get; set; } |
| 4 | 13 | | public string Url { get; set; } |
| 2 | 14 | | public DateTime CreatedAt { get; set; } |
| | 15 | |
|
| 4 | 16 | | public List<WebhookEventType> Events { get; set; } |
| 6 | 17 | | public WebhookAuthentication Authentication { get; set; } |
| | 18 | |
|
| 0 | 19 | | public List<WebhookCall> Calls { get; set; } |
| | 20 | |
|
| 4 | 21 | | private WebhookSubscription() { } |
| | 22 | |
|
| 2 | 23 | | public WebhookSubscription(Guid institutionId, string name, string url, List<WebhookEventType> events, string apiKey |
| | 24 | | { |
| 2 | 25 | | Id = Guid.CreateVersion7(); |
| 2 | 26 | | InstitutionId = institutionId; |
| 2 | 27 | | Name = name; |
| 2 | 28 | | Url = url; |
| 2 | 29 | | Events = events; |
| 2 | 30 | | CreatedAt = DateTime.UtcNow; |
| 2 | 31 | | Authentication = new WebhookAuthentication(Id, WebhookAuthenticationType.ApiKey, apiKey); |
| 2 | 32 | | } |
| | 33 | |
|
| | 34 | | public CreateWebhookSubscriptionOut ToOut() |
| | 35 | | { |
| 2 | 36 | | return new() |
| 2 | 37 | | { |
| 2 | 38 | | Id = Id, |
| 2 | 39 | | }; |
| | 40 | | } |
| | 41 | |
|
| | 42 | | public GetWebhooksOut ToGetWebhooksOut() |
| | 43 | | { |
| 0 | 44 | | return new() |
| 0 | 45 | | { |
| 0 | 46 | | Id = Id, |
| 0 | 47 | | Name = Name, |
| 0 | 48 | | Url = Url, |
| 0 | 49 | | CreatedAt = CreatedAt, |
| 0 | 50 | | CallsCount = Calls.Count, |
| 0 | 51 | | }; |
| | 52 | | } |
| | 53 | |
|
| | 54 | | public GetWebhookOut ToGetWebhookOut() |
| | 55 | | { |
| 0 | 56 | | return new() |
| 0 | 57 | | { |
| 0 | 58 | | Id = Id, |
| 0 | 59 | | Url = Url, |
| 0 | 60 | | Name = Name, |
| 0 | 61 | | CreatedAt = CreatedAt, |
| 0 | 62 | | CallsCount = Calls.Count, |
| 0 | 63 | | EventsCount = Events.Count, |
| 0 | 64 | | AuthenticationType = Authentication.Type, |
| 0 | 65 | | Calls = Calls.ConvertAll(x => x.ToGetWebhookCallOut()) |
| 0 | 66 | | }; |
| | 67 | | } |
| | 68 | | } |