From 04f899e8414aafd0c774502242100d1e4e6bb28e Mon Sep 17 00:00:00 2001 From: James Gunn Date: Tue, 17 Dec 2024 17:37:02 +0000 Subject: [PATCH] Create webhook messages when events are saved (#1753) --- .../Operations/SetCpdInductionStatus.cs | 2 +- .../Operations/SetWelshInductionStatus.cs | 2 +- .../Pages/CheckAnswers.cshtml.cs | 2 +- .../TeachingRecordSystem.Core/CacheKeys.cs | 2 + .../DataStore/Postgres/TrsDbContext.cs | 26 +++- .../Postgres/TrsDesignTimeDbContextFactory.cs | 5 +- .../TeachingRecordSystem.Core/Extensions.cs | 11 ++ .../Jobs/SendEytsAwardedEmailJob.cs | 2 +- .../Jobs/SendInductionCompletedEmailJob.cs | 2 +- .../SendInternationalQtsAwardedEmailJob.cs | 2 +- .../Jobs/SendQtsAwardedEmailJob.cs | 2 +- .../Services/Webhooks/EventMapperRegistry.cs | 49 ++++++++ .../Webhooks/WebhookMessageFactory.cs | 115 ++++++++++++++++++ .../Extensions.cs | 1 + .../Alerts/AddAlert/CheckAnswers.cshtml.cs | 2 +- .../Alerts/CloseAlert/CheckAnswers.cshtml.cs | 2 +- .../Alerts/DeleteAlert/CheckAnswers.cshtml.cs | 2 +- .../EditAlert/Details/CheckAnswers.cshtml.cs | 2 +- .../EditAlert/EndDate/CheckAnswers.cshtml.cs | 2 +- .../EditAlert/Link/CheckAnswers.cshtml.cs | 2 +- .../StartDate/CheckAnswers.cshtml.cs | 2 +- .../Alerts/ReopenAlert/CheckAnswers.cshtml.cs | 2 +- .../Pages/ApiKeys/AddApiKey.cshtml.cs | 2 +- .../Pages/ApiKeys/EditApiKey.cshtml.cs | 2 +- .../AddApplicationUser.cshtml.cs | 2 +- .../EditApplicationUser.cshtml.cs | 2 +- .../Pages/Mqs/AddMq/CheckAnswers.cshtml.cs | 2 +- .../Pages/Mqs/DeleteMq/Confirm.cshtml.cs | 2 +- .../Mqs/EditMq/Provider/Confirm.cshtml.cs | 2 +- .../Mqs/EditMq/Specialism/Confirm.cshtml.cs | 2 +- .../Mqs/EditMq/StartDate/Confirm.cshtml.cs | 2 +- .../Pages/Mqs/EditMq/Status/Confirm.cshtml.cs | 2 +- .../Pages/Users/AddUser/Confirm.cshtml.cs | 2 +- .../Pages/Users/EditUser.cshtml.cs | 6 +- .../TeachingRecordSystem.Worker/Program.cs | 3 +- .../PersonDetail/ChangeLogAlertEventsTests.cs | 16 +-- ...ngeLogMandatoryQualificationEventsTests.cs | 14 +-- .../TestData.CreateApiKey.cs | 2 +- .../TestData.CreateApplicationUser.cs | 2 +- .../TestData.CreatePerson.cs | 8 +- .../TestData.DeleteMandatoryQualification.cs | 2 +- 41 files changed, 255 insertions(+), 59 deletions(-) create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/EventMapperRegistry.cs create mode 100644 TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookMessageFactory.cs diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetCpdInductionStatus.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetCpdInductionStatus.cs index 41674b48f..747e076eb 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetCpdInductionStatus.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetCpdInductionStatus.cs @@ -103,7 +103,7 @@ public async Task> HandleAsync(SetCpdIndu if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); } await dbContext.SaveChangesAsync(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetWelshInductionStatus.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetWelshInductionStatus.cs index 5e0ee3b38..c8d8408ac 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetWelshInductionStatus.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Implementation/Operations/SetWelshInductionStatus.cs @@ -65,7 +65,7 @@ public async Task> HandleAsync(SetWelsh if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); } await dbContext.SaveChangesAsync(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/CheckAnswers.cshtml.cs index 892946fff..5799a6cfd 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.AuthorizeAccess/Pages/CheckAnswers.cshtml.cs @@ -57,7 +57,7 @@ public async Task OnPostAsync() }; dbContext.SupportTasks.Add(supportTask); - dbContext.AddEvent(new SupportTaskCreatedEvent() + await dbContext.AddEventAndBroadcastAsync(new SupportTaskCreatedEvent() { EventId = Guid.NewGuid(), CreatedUtc = clock.UtcNow, diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/CacheKeys.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/CacheKeys.cs index 9c8020b77..b8f23dad8 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/CacheKeys.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/CacheKeys.cs @@ -29,4 +29,6 @@ public static class CacheKeys public static object GetSubjectTitleKey(string title) => $"subjects_{title}"; public static object PersonInfo(Guid personId) => $"person_info:{personId}"; + + public static object EnabledWebhookEndpoints() => "webhook_endpoints"; } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs index 234ceb4b1..15efaafee 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs @@ -1,9 +1,11 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.EntityFrameworkCore.Metadata.Conventions; +using Microsoft.Extensions.DependencyInjection; using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure; using OpenIddict.EntityFrameworkCore.Models; using TeachingRecordSystem.Core.DataStore.Postgres.Models; using TeachingRecordSystem.Core.Infrastructure.EntityFramework; +using TeachingRecordSystem.Core.Services.Webhooks; using Establishment = TeachingRecordSystem.Core.DataStore.Postgres.Models.Establishment; using User = TeachingRecordSystem.Core.DataStore.Postgres.Models.User; @@ -11,7 +13,15 @@ namespace TeachingRecordSystem.Core.DataStore.Postgres; public class TrsDbContext : DbContext { - public TrsDbContext(DbContextOptions options) + private readonly IServiceProvider? _serviceProvider; + + public TrsDbContext(DbContextOptions options, IServiceProvider serviceProvider) + : base(options) + { + _serviceProvider = serviceProvider; + } + + private TrsDbContext(DbContextOptions options) : base(options) { } @@ -121,9 +131,19 @@ public static void ConfigureOptions(DbContextOptionsBuilder optionsBuilder, stri }); } - public void AddEvent(EventBase @event, DateTime? inserted = null) + public async Task AddEventAndBroadcastAsync(EventBase @event) + { + Events.Add(Event.FromEventBase(@event, inserted: null)); + + _ = _serviceProvider ?? throw new InvalidOperationException("No ServiceProvider on DbContext."); + var webhookMessageFactory = _serviceProvider.GetRequiredService(); + var messages = await webhookMessageFactory.CreateMessagesAsync(this, @event, _serviceProvider); + WebhookMessages.AddRange(messages); + } + + public void AddEventWithoutBroadcast(EventBase @event) { - Events.Add(Event.FromEventBase(@event, inserted)); + Events.Add(Event.FromEventBase(@event, inserted: null)); } protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder) diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDesignTimeDbContextFactory.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDesignTimeDbContextFactory.cs index 9edba3155..14c3561f0 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDesignTimeDbContextFactory.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDesignTimeDbContextFactory.cs @@ -13,9 +13,6 @@ public TrsDbContext CreateDbContext(string[] args) var connectionString = configuration.GetPostgresConnectionString(); - var optionsBuilder = new DbContextOptionsBuilder(); - TrsDbContext.ConfigureOptions(optionsBuilder, connectionString); - - return new TrsDbContext(optionsBuilder.Options); + return TrsDbContext.Create(connectionString); } } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs index c9eb27463..74ecb972e 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs @@ -3,12 +3,14 @@ using Microsoft.ApplicationInsights.Extensibility; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Hosting; using Npgsql; using Serilog; using Serilog.Formatting.Compact; using TeachingRecordSystem.Core.DataStore.Postgres; using TeachingRecordSystem.Core.Jobs.Scheduling; +using TeachingRecordSystem.Core.Services.Webhooks; namespace TeachingRecordSystem.Core; @@ -72,6 +74,15 @@ public static IHostApplicationBuilder AddHangfire(this IHostApplicationBuilder b return builder; } + public static IHostApplicationBuilder AddWebhookMessageFactory(this IHostApplicationBuilder builder) + { + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); + builder.Services.TryAddSingleton(); + + return builder; + } + public static void ConfigureSerilog( this LoggerConfiguration config, IHostEnvironment environment, diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendEytsAwardedEmailJob.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendEytsAwardedEmailJob.cs index 6d7b07f47..1de863d29 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendEytsAwardedEmailJob.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendEytsAwardedEmailJob.cs @@ -49,7 +49,7 @@ public async Task ExecuteAsync(Guid eytsAwardedEmailsJobId, Guid personId) await _notificationSender.SendEmailAsync(EytsAwardedEmailConfirmationTemplateId, item.EmailAddress, item.Personalization); item.EmailSent = true; - _dbContext.AddEvent(new EytsAwardedEmailSentEvent + _dbContext.AddEventWithoutBroadcast(new EytsAwardedEmailSentEvent { EventId = Guid.NewGuid(), EytsAwardedEmailsJobId = eytsAwardedEmailsJobId, diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInductionCompletedEmailJob.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInductionCompletedEmailJob.cs index aa00c2166..10425f36f 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInductionCompletedEmailJob.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInductionCompletedEmailJob.cs @@ -49,7 +49,7 @@ public async Task ExecuteAsync(Guid inductionCompletedEmailsJobId, Guid personId await _notificationSender.SendEmailAsync(InductionCompletedEmailConfirmationTemplateId, item.EmailAddress, item.Personalization); item.EmailSent = true; - _dbContext.AddEvent(new InductionCompletedEmailSentEvent + _dbContext.AddEventWithoutBroadcast(new InductionCompletedEmailSentEvent { EventId = Guid.NewGuid(), InductionCompletedEmailsJobId = inductionCompletedEmailsJobId, diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInternationalQtsAwardedEmailJob.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInternationalQtsAwardedEmailJob.cs index 92dff490e..ec618d63a 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInternationalQtsAwardedEmailJob.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInternationalQtsAwardedEmailJob.cs @@ -49,7 +49,7 @@ public async Task ExecuteAsync(Guid internationalQtsAwardedEmailsJobId, Guid per await _notificationSender.SendEmailAsync(InternationalQtsAwardedEmailConfirmationTemplateId, item.EmailAddress, item.Personalization); item.EmailSent = true; - _dbContext.AddEvent(new InternationalQtsAwardedEmailSentEvent + _dbContext.AddEventWithoutBroadcast(new InternationalQtsAwardedEmailSentEvent { EventId = Guid.NewGuid(), InternationalQtsAwardedEmailsJobId = internationalQtsAwardedEmailsJobId, diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendQtsAwardedEmailJob.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendQtsAwardedEmailJob.cs index cfcf85df1..b77a967e8 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendQtsAwardedEmailJob.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendQtsAwardedEmailJob.cs @@ -49,7 +49,7 @@ public async Task ExecuteAsync(Guid qtsAwardedEmailsJobId, Guid personId) await _notificationSender.SendEmailAsync(QtsAwardedEmailConfirmationTemplateId, item.EmailAddress, item.Personalization); item.EmailSent = true; - _dbContext.AddEvent(new QtsAwardedEmailSentEvent + _dbContext.AddEventWithoutBroadcast(new QtsAwardedEmailSentEvent { EventId = Guid.NewGuid(), QtsAwardedEmailsJobId = qtsAwardedEmailsJobId, diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/EventMapperRegistry.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/EventMapperRegistry.cs new file mode 100644 index 000000000..a27592f71 --- /dev/null +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/EventMapperRegistry.cs @@ -0,0 +1,49 @@ +using System.Diagnostics.CodeAnalysis; +using TeachingRecordSystem.Core.ApiSchema.V3; + +namespace TeachingRecordSystem.Core.Services.Webhooks; + +public class EventMapperRegistry +{ + private sealed record MapperKey(Type EventType, string CloudEventType, string ApiVersion); + + private sealed record MapperValue(Type MapperType, Type DataType); + + private readonly Dictionary _mappers = DiscoverMappers(); + + public Type? GetMapperType(Type eventType, string cloudEventType, string apiVersion, [MaybeNull] out Type dataType) + { + if (_mappers.TryGetValue(new(eventType, cloudEventType, apiVersion), out var result)) + { + dataType = result.DataType; + return result.MapperType; + } + + dataType = null; + return null; + } + + private static Dictionary DiscoverMappers() + { + var mapperTypes = typeof(EventMapperRegistry).Assembly.GetTypes() + .Where(t => t.IsPublic && !t.IsAbstract && t.GetInterfaces().Any(i => + i.IsGenericType && i.GetGenericTypeDefinition().IsAssignableTo(typeof(IEventMapper<,>)))); + + var mappers = new Dictionary(); + + foreach (var type in mapperTypes) + { + var mapperTypeArgs = type.GetInterface(typeof(IEventMapper<,>).Name)!.GetGenericArguments(); + var eventType = mapperTypeArgs[0]; + var dataType = mapperTypeArgs[1]; + + var cloudEventType = (string)dataType.GetProperty("CloudEventType")!.GetValue(null)!; + + var version = type.Namespace!.Split('.').SkipWhile(ns => ns != "V3").Skip(1).First().TrimStart('V'); + + mappers.Add(new MapperKey(eventType, cloudEventType, version), new MapperValue(type, dataType)); + } + + return mappers; + } +} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookMessageFactory.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookMessageFactory.cs new file mode 100644 index 000000000..95cd89ff6 --- /dev/null +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/Services/Webhooks/WebhookMessageFactory.cs @@ -0,0 +1,115 @@ +using System.Text.Json; +using System.Text.Json.Serialization.Metadata; +using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.DependencyInjection; +using TeachingRecordSystem.Core.ApiSchema.V3; +using TeachingRecordSystem.Core.DataStore.Postgres; +using TeachingRecordSystem.Core.DataStore.Postgres.Models; +using TeachingRecordSystem.Core.Infrastructure.Json; + +namespace TeachingRecordSystem.Core.Services.Webhooks; + +public class WebhookMessageFactory(EventMapperRegistry eventMapperRegistry, IClock clock, IMemoryCache memoryCache) +{ + private static readonly TimeSpan _webhookEndpointsCacheDuration = TimeSpan.FromMinutes(1); + + private static readonly JsonSerializerOptions _serializerOptions = + new JsonSerializerOptions(JsonSerializerDefaults.Web) + { + TypeInfoResolver = new DefaultJsonTypeInfoResolver() + { + Modifiers = + { + Modifiers.OptionProperties + } + } + }; + + public async Task> CreateMessagesAsync( + TrsDbContext dbContext, + EventBase @event, + IServiceProvider serviceProvider) + { + var endpoints = await memoryCache.GetOrCreateAsync( + CacheKeys.EnabledWebhookEndpoints(), + async e => + { + e.SetAbsoluteExpiration(_webhookEndpointsCacheDuration); + return await dbContext.WebhookEndpoints.AsNoTracking().Where(e => e.Enabled).ToArrayAsync(); + }); + + var endpointCloudEventTypeVersions = endpoints! + .SelectMany(e => + e.CloudEventTypes.Select(t => (Version: e.ApiVersion, CloudEventType: t, e.WebhookEndpointId))) + .GroupBy(t => (t.Version, t.CloudEventType), t => t.WebhookEndpointId) + .ToDictionary(g => g.Key, g => g.AsEnumerable()); + + var messages = new List(); + + foreach (var (version, cloudEventType) in endpointCloudEventTypeVersions.Keys) + { + var mapperType = eventMapperRegistry.GetMapperType(@event.GetType(), cloudEventType, version, out var dataType); + if (mapperType is null) + { + continue; + } + + var payload = await MapEventAsync(mapperType, dataType!); + if (payload is null) + { + continue; + } + + var serializedPayload = JsonSerializer.SerializeToElement(payload, _serializerOptions); + + messages.AddRange(endpointCloudEventTypeVersions[(version, cloudEventType)].Select(epId => + { + var id = Guid.NewGuid(); + + return new WebhookMessage + { + WebhookMessageId = id, + WebhookEndpointId = epId, + CloudEventId = id.ToString(), + CloudEventType = cloudEventType, + Timestamp = clock.UtcNow, + ApiVersion = version, + Data = serializedPayload, + NextDeliveryAttempt = clock.UtcNow, + Delivered = null, + DeliveryAttempts = [], + DeliveryErrors = [] + }; + })); + } + + return messages; + + Task MapEventAsync(Type mapperType, Type dataType) + { + var mapper = ActivatorUtilities.CreateInstance(serviceProvider, mapperType); + + var eventType = @event.GetType(); + + var wrappedMapper = (IEventMapper)ActivatorUtilities.CreateInstance( + serviceProvider, + typeof(WrappedMapper<,>).MakeGenericType(eventType, dataType), + mapper); + + return wrappedMapper.MapEventAsync(@event); + } + } + + private interface IEventMapper + { + Task MapEventAsync(EventBase @event); + } + + private class WrappedMapper(IEventMapper innerMapper) : IEventMapper + where TEvent : EventBase + where TData : IWebhookMessageData + { + public async Task MapEventAsync(EventBase @event) => + await innerMapper.MapEventAsync((TEvent)@event); + } +} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.ServiceDefaults/Extensions.cs b/TeachingRecordSystem/src/TeachingRecordSystem.ServiceDefaults/Extensions.cs index d0d378fb9..f1dd94cb9 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.ServiceDefaults/Extensions.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.ServiceDefaults/Extensions.cs @@ -23,6 +23,7 @@ public static IHostApplicationBuilder AddServiceDefaults( builder.AddDatabase(); builder.AddHangfire(); builder.AddBackgroundWorkScheduler(); + builder.AddWebhookMessageFactory(); builder.Services.AddHealthChecks().AddNpgSql(sp => sp.GetRequiredService()); builder.Services.AddDatabaseDeveloperPageExceptionFilter(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs index b06c413ca..0224e4441 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AddAlert/CheckAnswers.cshtml.cs @@ -71,7 +71,7 @@ public async Task OnPostAsync() out var createdEvent); dbContext.Alerts.Add(alert); - dbContext.AddEvent(createdEvent); + await dbContext.AddEventAndBroadcastAsync(createdEvent); await dbContext.SaveChangesAsync(); await JourneyInstance!.CompleteAsync(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/CheckAnswers.cshtml.cs index 701fdf539..1579c5c07 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/CloseAlert/CheckAnswers.cshtml.cs @@ -78,7 +78,7 @@ public async Task OnPostAsync() Changes = AlertUpdatedEventChanges.EndDate }; - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml.cs index ed54071ce..5330b29f6 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/DeleteAlert/CheckAnswers.cshtml.cs @@ -59,7 +59,7 @@ public async Task OnPostAsync() clock.UtcNow, out var deletedEvent); - dbContext.AddEvent(deletedEvent); + await dbContext.AddEventAndBroadcastAsync(deletedEvent); await dbContext.SaveChangesAsync(); await JourneyInstance!.CompleteAsync(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/Details/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/Details/CheckAnswers.cshtml.cs index 1be9da9b6..fb9ac4f1b 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/Details/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/Details/CheckAnswers.cshtml.cs @@ -60,7 +60,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/CheckAnswers.cshtml.cs index 7d27c7150..c9005b0af 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/EndDate/CheckAnswers.cshtml.cs @@ -60,7 +60,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/Link/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/Link/CheckAnswers.cshtml.cs index cef33ca8d..cc8b61fdb 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/Link/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/Link/CheckAnswers.cshtml.cs @@ -64,7 +64,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/StartDate/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/StartDate/CheckAnswers.cshtml.cs index b28e4a92c..ab03282ec 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/StartDate/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/EditAlert/StartDate/CheckAnswers.cshtml.cs @@ -60,7 +60,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/ReopenAlert/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/ReopenAlert/CheckAnswers.cshtml.cs index 5587aa595..06b31bed3 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/ReopenAlert/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/ReopenAlert/CheckAnswers.cshtml.cs @@ -66,7 +66,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApiKeys/AddApiKey.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApiKeys/AddApiKey.cshtml.cs index 680a0df1b..14425f7a8 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApiKeys/AddApiKey.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApiKeys/AddApiKey.cshtml.cs @@ -54,7 +54,7 @@ public async Task OnPostAsync() RaisedBy = User.GetUserId(), ApiKey = Core.Events.Models.ApiKey.FromModel(apiKey) }; - dbContext.AddEvent(@event); + await dbContext.AddEventAndBroadcastAsync(@event); try { diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApiKeys/EditApiKey.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApiKeys/EditApiKey.cshtml.cs index e1784661d..0d704bb48 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApiKeys/EditApiKey.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApiKeys/EditApiKey.cshtml.cs @@ -48,7 +48,7 @@ public async Task OnPostExpireAsync() OldApiKey = oldApiKey, Changes = ApiKeyUpdatedEventChanges.Expires }; - dbContext.AddEvent(@event); + await dbContext.AddEventAndBroadcastAsync(@event); await dbContext.SaveChangesAsync(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApplicationUsers/AddApplicationUser.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApplicationUsers/AddApplicationUser.cshtml.cs index 91c0af6ea..718f670e0 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApplicationUsers/AddApplicationUser.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApplicationUsers/AddApplicationUser.cshtml.cs @@ -37,7 +37,7 @@ public async Task OnPostAsync() dbContext.ApplicationUsers.Add(newUser); - dbContext.AddEvent(new ApplicationUserCreatedEvent() + await dbContext.AddEventAndBroadcastAsync(new ApplicationUserCreatedEvent() { EventId = Guid.NewGuid(), ApplicationUser = Core.Events.Models.ApplicationUser.FromModel(newUser), diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApplicationUsers/EditApplicationUser.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApplicationUsers/EditApplicationUser.cshtml.cs index c971e3e94..6e3ee809d 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApplicationUsers/EditApplicationUser.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/ApplicationUsers/EditApplicationUser.cshtml.cs @@ -229,7 +229,7 @@ key is nameof(ClientId) or nameof(ClientSecret) or nameof(RedirectUris) or nameo OldApplicationUser = oldApplicationUser, Changes = changes }; - dbContext.AddEvent(@event); + await dbContext.AddEventAndBroadcastAsync(@event); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/AddMq/CheckAnswers.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/AddMq/CheckAnswers.cshtml.cs index 02767977b..5c1ec14ee 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/AddMq/CheckAnswers.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/AddMq/CheckAnswers.cshtml.cs @@ -42,7 +42,7 @@ public async Task OnPostAsync() out var createdEvent); dbContext.MandatoryQualifications.Add(qualification); - dbContext.AddEvent(createdEvent); + await dbContext.AddEventAndBroadcastAsync(createdEvent); await dbContext.SaveChangesAsync(); await JourneyInstance!.CompleteAsync(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/DeleteMq/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/DeleteMq/Confirm.cshtml.cs index cd8accd5e..0ec1cea93 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/DeleteMq/Confirm.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/DeleteMq/Confirm.cshtml.cs @@ -60,7 +60,7 @@ public async Task OnPostAsync() clock.UtcNow, out var deletedEvent); - dbContext.AddEvent(deletedEvent); + await dbContext.AddEventAndBroadcastAsync(deletedEvent); await dbContext.SaveChangesAsync(); await JourneyInstance!.CompleteAsync(); diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Provider/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Provider/Confirm.cshtml.cs index 9cbf5965f..4ebdc80b2 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Provider/Confirm.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Provider/Confirm.cshtml.cs @@ -64,7 +64,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Specialism/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Specialism/Confirm.cshtml.cs index 1bedaaf58..015a80fed 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Specialism/Confirm.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Specialism/Confirm.cshtml.cs @@ -59,7 +59,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/StartDate/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/StartDate/Confirm.cshtml.cs index 6fdc4b700..a69936edc 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/StartDate/Confirm.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/StartDate/Confirm.cshtml.cs @@ -59,7 +59,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Status/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Status/Confirm.cshtml.cs index 8df91abeb..c9a2fdefe 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Status/Confirm.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Mqs/EditMq/Status/Confirm.cshtml.cs @@ -73,7 +73,7 @@ public async Task OnPostAsync() if (updatedEvent is not null) { - dbContext.AddEvent(updatedEvent); + await dbContext.AddEventAndBroadcastAsync(updatedEvent); await dbContext.SaveChangesAsync(); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/AddUser/Confirm.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/AddUser/Confirm.cshtml.cs index 18ef832bd..1f9e3bfc6 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/AddUser/Confirm.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/AddUser/Confirm.cshtml.cs @@ -80,7 +80,7 @@ public async Task OnPostAsync() dbContext.Users.Add(newUser); - dbContext.AddEvent(new UserAddedEvent() + await dbContext.AddEventAndBroadcastAsync(new UserAddedEvent() { EventId = Guid.NewGuid(), User = Core.Events.Models.User.FromModel(newUser), diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/EditUser.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/EditUser.cshtml.cs index d0ac111dd..48edf362c 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/EditUser.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/EditUser.cshtml.cs @@ -83,7 +83,7 @@ public async Task OnPostAsync() user.Roles = newRoles; user.Name = Name!; - dbContext.AddEvent(new UserUpdatedEvent + await dbContext.AddEventAndBroadcastAsync(new UserUpdatedEvent { EventId = Guid.NewGuid(), User = Core.Events.Models.User.FromModel(user), @@ -110,7 +110,7 @@ public async Task OnPostDeactivateAsync() user.Active = false; - dbContext.AddEvent(new UserDeactivatedEvent + await dbContext.AddEventAndBroadcastAsync(new UserDeactivatedEvent { EventId = Guid.NewGuid(), User = Core.Events.Models.User.FromModel(user), @@ -135,7 +135,7 @@ public async Task OnPostActivateAsync() user.Active = true; - dbContext.AddEvent(new UserActivatedEvent + await dbContext.AddEventAndBroadcastAsync(new UserActivatedEvent { EventId = Guid.NewGuid(), User = Core.Events.Models.User.FromModel(user), diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Worker/Program.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Worker/Program.cs index f919d89ff..c1b4e774f 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.Worker/Program.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Worker/Program.cs @@ -44,7 +44,8 @@ .AddIdentityApi() .AddNameSynonyms() .AddDqtOutboxMessageProcessorService() - .AddWebhookDeliveryService(); + .AddWebhookDeliveryService() + .AddWebhookMessageFactory(); var crmServiceClient = new ServiceClient(builder.Configuration.GetRequiredValue("ConnectionStrings:Crm")) { diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/ChangeLogAlertEventsTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/ChangeLogAlertEventsTests.cs index e360c3eef..1266ee8c5 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/ChangeLogAlertEventsTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/ChangeLogAlertEventsTests.cs @@ -923,7 +923,7 @@ private async Task CreateAlertCreatedEventFromDqtAsync(Guid p await WithDbContext(async dbContext => { - dbContext.AddEvent(alertCreatedEvent); + dbContext.AddEventWithoutBroadcast(alertCreatedEvent); await dbContext.SaveChangesAsync(); }); @@ -956,7 +956,7 @@ private async Task CreateAlertCreatedEventFromTrsAsync(Guid p await WithDbContext(async dbContext => { - dbContext.AddEvent(alertCreatedEvent); + dbContext.AddEventWithoutBroadcast(alertCreatedEvent); await dbContext.SaveChangesAsync(); }); @@ -987,7 +987,7 @@ private async Task CreateAlertDeletedEventAsync(Guid personId await WithDbContext(async dbContext => { - dbContext.AddEvent(alertDeletedEvent); + dbContext.AddEventWithoutBroadcast(alertDeletedEvent); await dbContext.SaveChangesAsync(); }); @@ -1009,7 +1009,7 @@ private async Task CreateAlertDqtDeactivatedEventAsync await WithDbContext(async dbContext => { - dbContext.AddEvent(alertDqtDeactivatedEvent); + dbContext.AddEventWithoutBroadcast(alertDqtDeactivatedEvent); await dbContext.SaveChangesAsync(); }); @@ -1032,7 +1032,7 @@ private async Task CreateAlertDqtImportedEventAsync(Guid await WithDbContext(async dbContext => { - dbContext.AddEvent(alertDqtImportedEvent); + dbContext.AddEventWithoutBroadcast(alertDqtImportedEvent); await dbContext.SaveChangesAsync(); }); @@ -1054,7 +1054,7 @@ private async Task CreateAlertDqtReactivatedEventAsync await WithDbContext(async dbContext => { - dbContext.AddEvent(alertDqtReactivatedEvent); + dbContext.AddEventWithoutBroadcast(alertDqtReactivatedEvent); await dbContext.SaveChangesAsync(); }); @@ -1091,7 +1091,7 @@ private async Task CreateAlertMigratedEventAsync(Guid person await WithDbContext(async dbContext => { - dbContext.AddEvent(alertMigratedEvent); + dbContext.AddEventWithoutBroadcast(alertMigratedEvent); await dbContext.SaveChangesAsync(); }); @@ -1121,7 +1121,7 @@ private async Task CreateAlertUpdatedEventAsync(Guid personId await WithDbContext(async dbContext => { - dbContext.AddEvent(alertUpdatedEvent); + dbContext.AddEventWithoutBroadcast(alertUpdatedEvent); await dbContext.SaveChangesAsync(); }); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/ChangeLogMandatoryQualificationEventsTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/ChangeLogMandatoryQualificationEventsTests.cs index 7ed5672ef..3abcad51e 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/ChangeLogMandatoryQualificationEventsTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Persons/PersonDetail/ChangeLogMandatoryQualificationEventsTests.cs @@ -342,7 +342,7 @@ await TestData.ReferenceDataCache.GetMqEstablishmentByIdAsync(mqEstablishmentId) EndDate = qualification.EndDate } }; - dbContext.AddEvent(reactivatedEvent); + dbContext.AddEventWithoutBroadcast(reactivatedEvent); await dbContext.SaveChangesAsync(); }); @@ -388,7 +388,7 @@ await WithDbContext(async dbContext => MandatoryQualification = EventModels.MandatoryQualification.FromModel(mq), Changes = MandatoryQualificationMigratedEventChanges.None }; - dbContext.AddEvent(migratedEvent); + dbContext.AddEventWithoutBroadcast(migratedEvent); await dbContext.SaveChangesAsync(); }); @@ -434,7 +434,7 @@ await WithDbContext(async dbContext => MandatoryQualification = EventModels.MandatoryQualification.FromModel(mq), Changes = MandatoryQualificationMigratedEventChanges.None }; - dbContext.AddEvent(migratedEvent); + dbContext.AddEventWithoutBroadcast(migratedEvent); await dbContext.SaveChangesAsync(); }); @@ -483,7 +483,7 @@ public async Task Person_WithMandatoryQualificationMigratedEventWithChangedProvi MandatoryQualification = EventModels.MandatoryQualification.FromModel(mq), Changes = MandatoryQualificationMigratedEventChanges.Provider }; - dbContext.AddEvent(migratedEvent); + dbContext.AddEventWithoutBroadcast(migratedEvent); await dbContext.SaveChangesAsync(); @@ -539,7 +539,7 @@ public async Task Person_WithMandatoryQualificationMigratedEventWithChangedSpeci MandatoryQualification = EventModels.MandatoryQualification.FromModel(mq), Changes = MandatoryQualificationMigratedEventChanges.Specialism }; - dbContext.AddEvent(migratedEvent); + dbContext.AddEventWithoutBroadcast(migratedEvent); await dbContext.SaveChangesAsync(); @@ -1015,7 +1015,7 @@ await TestData.ReferenceDataCache.GetMqEstablishmentByIdAsync(mqEstablishmentId) EndDate = qualification.EndDate } }; - dbContext.AddEvent(deletedEvent); + dbContext.AddEventWithoutBroadcast(deletedEvent); await dbContext.SaveChangesAsync(); }); @@ -1105,7 +1105,7 @@ await TestData.ReferenceDataCache.GetMqEstablishmentByIdAsync(mqEstablishmentId) null, Changes = changes }; - dbContext.AddEvent(updatedEvent); + dbContext.AddEventWithoutBroadcast(updatedEvent); await dbContext.SaveChangesAsync(); }); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreateApiKey.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreateApiKey.cs index 263fd4562..3bd991d45 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreateApiKey.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreateApiKey.cs @@ -28,7 +28,7 @@ public Task CreateApiKeyAsync(Guid applicationUserId, bool expired = fal RaisedBy = SystemUser.SystemUserId, ApiKey = Core.Events.Models.ApiKey.FromModel(apiKey) }; - dbContext.AddEvent(@event); + dbContext.AddEventWithoutBroadcast(@event); await dbContext.SaveChangesAsync(); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreateApplicationUser.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreateApplicationUser.cs index a7e9368cd..f114caa02 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreateApplicationUser.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreateApplicationUser.cs @@ -64,7 +64,7 @@ public async Task CreateApplicationUserAsync( CreatedUtc = Clock.UtcNow, ApplicationUser = EventModels.ApplicationUser.FromModel(user) }; - dbContext.AddEvent(@event); + dbContext.AddEventWithoutBroadcast(@event); await dbContext.SaveChangesAsync(); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreatePerson.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreatePerson.cs index ee2b12885..fff9712d9 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreatePerson.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.CreatePerson.cs @@ -850,7 +850,7 @@ public CreatePersonAlertBuilder WithCreatedByUser(EventModels.RaisedByUserInfo u out var @createdEvent); dbContext.Alerts.Add(alert); - dbContext.AddEvent(createdEvent); + dbContext.AddEventWithoutBroadcast(createdEvent); return (alert.AlertId, [createdEvent]); } @@ -1023,7 +1023,7 @@ await dbContext.MandatoryQualificationProviders.SingleAsync(p => p.MandatoryQual DqtState = 0 }; - dbContext.AddEvent(createdEvent); + dbContext.AddEventWithoutBroadcast(createdEvent); events.Add(createdEvent); } else @@ -1053,7 +1053,7 @@ await dbContext.MandatoryQualificationProviders.SingleAsync(p => p.MandatoryQual } }; - dbContext.AddEvent(createdEvent); + dbContext.AddEventWithoutBroadcast(createdEvent); events.Add(createdEvent); } @@ -1138,7 +1138,7 @@ internal IReadOnlyCollection Execute( if (@event is not null) { - dbContext.AddEvent(@event); + dbContext.AddEventWithoutBroadcast(@event); return [@event]; } diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.DeleteMandatoryQualification.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.DeleteMandatoryQualification.cs index c0f8f2c8e..dde6b938b 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.DeleteMandatoryQualification.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/TestData.DeleteMandatoryQualification.cs @@ -60,7 +60,7 @@ await ReferenceDataCache.GetMqEstablishmentByIdAsync(mqEstablishmentId) : } : null }; - dbContext.AddEvent(deletedEvent); + dbContext.AddEventWithoutBroadcast(deletedEvent); await dbContext.SaveChangesAsync(); });