| | 1 | | using Syki.Back.Features.Cross.LinkOldNotifications; |
| | 2 | |
|
| | 3 | | namespace Syki.Back.Features.Academic.CreateStudent; |
| | 4 | |
|
| | 5 | | [DomainEvent(nameof(SykiStudent), "Aluno criado")] |
| 1802 | 6 | | public record StudentCreatedDomainEvent(Guid UserId, Guid InstitutionId) : IDomainEvent; |
| | 7 | |
|
| | 8 | | public class StudentCreatedDomainEventHandler(SykiDbContext ctx) : IDomainEventHandler<StudentCreatedDomainEvent> |
| | 9 | | { |
| | 10 | | public async Task Handle(Guid institutionId, DomainEventId eventId, StudentCreatedDomainEvent evt) |
| | 11 | | { |
| | 12 | | ctx.AddCommand(institutionId, new LinkOldNotificationsCommand(evt.InstitutionId, evt.UserId), eventId: eventId); |
| | 13 | | ctx.AddCommand(institutionId, new SendStudentWelcomeEmailCommand(evt.InstitutionId, evt.UserId), eventId: eventI |
| | 14 | |
|
| | 15 | | var webhooks = await ctx.Webhooks |
| | 16 | | .Where(x => x.InstitutionId == institutionId && x.Events.Contains(WebhookEventType.StudentCreated)) |
| | 17 | | .Select(x => new { x.Id }) |
| | 18 | | .ToListAsync(); |
| | 19 | | foreach (var webhook in webhooks) |
| | 20 | | { |
| | 21 | | ctx.AddCommand(institutionId, new CreateStudentCreatedWebhookCallCommand(eventId, webhook.Id, evt.UserId), e |
| | 22 | | } |
| | 23 | | } |
| | 24 | | } |