Skip to content

Commit

Permalink
Create webhook messages when events are saved
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Dec 17, 2024
1 parent c3e30cc commit 350b26c
Show file tree
Hide file tree
Showing 41 changed files with 255 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public async Task<ApiResult<SetCpdInductionStatusResult>> HandleAsync(SetCpdIndu

if (updatedEvent is not null)
{
dbContext.AddEvent(updatedEvent);
await dbContext.AddEventAndBroadcastAsync(updatedEvent);
}

await dbContext.SaveChangesAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task<ApiResult<SetWelshInductionStatusResult>> HandleAsync(SetWelsh

if (updatedEvent is not null)
{
dbContext.AddEvent(updatedEvent);
await dbContext.AddEventAndBroadcastAsync(updatedEvent);
}

await dbContext.SaveChangesAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<IActionResult> OnPostAsync()
};
dbContext.SupportTasks.Add(supportTask);

dbContext.AddEvent(new SupportTaskCreatedEvent()
await dbContext.AddEventAndBroadcastAsync(new SupportTaskCreatedEvent()
{
EventId = Guid.NewGuid(),
CreatedUtc = clock.UtcNow,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
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;

namespace TeachingRecordSystem.Core.DataStore.Postgres;

public class TrsDbContext : DbContext
{
public TrsDbContext(DbContextOptions<TrsDbContext> options)
private readonly IServiceProvider? _serviceProvider;

public TrsDbContext(DbContextOptions<TrsDbContext> options, IServiceProvider serviceProvider)
: base(options)
{
_serviceProvider = serviceProvider;
}

private TrsDbContext(DbContextOptions<TrsDbContext> options)
: base(options)
{
}
Expand Down Expand Up @@ -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<WebhookMessageFactory>();

Check failure on line 139 in TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs

View workflow job for this annotation

GitHub Actions / TeachingRecordSystem.Core.Tests test results

TeachingRecordSystem.Core.Tests.Jobs.SendInductionCompletedEmailJobTests ► Execute_WhenCalled_GetsTrnTokenSendsEmailAddsEventAndUpdatesDatabase

Failed test found in: TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/TestResults/_fv-az1198-760_2024-12-17_16_51_13.trx Error: System.InvalidOperationException : No service for type 'TeachingRecordSystem.Core.Services.Webhooks.WebhookMessageFactory' has been registered.
Raw output
System.InvalidOperationException : No service for type 'TeachingRecordSystem.Core.Services.Webhooks.WebhookMessageFactory' has been registered.
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at TeachingRecordSystem.Core.DataStore.Postgres.TrsDbContext.AddEventAndBroadcastAsync(EventBase event) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs:line 139
   at TeachingRecordSystem.Core.Jobs.SendInductionCompletedEmailJob.ExecuteAsync(Guid inductionCompletedEmailsJobId, Guid personId) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInductionCompletedEmailJob.cs:line 52
   at TeachingRecordSystem.Core.Tests.Jobs.SendInductionCompletedEmailJobTests.<>c.<<Execute_WhenCalled_GetsTrnTokenSendsEmailAddsEventAndUpdatesDatabase>b__1_0>d.MoveNext() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/SendInductionCompletedEmailJobTests.cs:line 85
--- End of stack trace from previous location ---
   at TeachingRecordSystem.TestCommon.DbFixture.<>c__DisplayClass13_0.<<WithDbContextAsync>b__0>d.MoveNext() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 35
--- End of stack trace from previous location ---
   at TeachingRecordSystem.TestCommon.DbFixture.WithDbContextAsync[T](Func`2 action) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 29
   at TeachingRecordSystem.TestCommon.DbFixture.WithDbContextAsync[T](Func`2 action) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 29

Check failure on line 139 in TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs

View workflow job for this annotation

GitHub Actions / TeachingRecordSystem.Core.Tests test results

TeachingRecordSystem.Core.Tests.Jobs.SendInternationalQtsAwardedEmailJobTests ► Execute_WhenCalled_GetsTrnTokenSendsEmailAddsEventAndUpdatesDatabase

Failed test found in: TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/TestResults/_fv-az1198-760_2024-12-17_16_51_13.trx Error: System.InvalidOperationException : No service for type 'TeachingRecordSystem.Core.Services.Webhooks.WebhookMessageFactory' has been registered.
Raw output
System.InvalidOperationException : No service for type 'TeachingRecordSystem.Core.Services.Webhooks.WebhookMessageFactory' has been registered.
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at TeachingRecordSystem.Core.DataStore.Postgres.TrsDbContext.AddEventAndBroadcastAsync(EventBase event) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs:line 139
   at TeachingRecordSystem.Core.Jobs.SendInternationalQtsAwardedEmailJob.ExecuteAsync(Guid internationalQtsAwardedEmailsJobId, Guid personId) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendInternationalQtsAwardedEmailJob.cs:line 52
   at TeachingRecordSystem.Core.Tests.Jobs.SendInternationalQtsAwardedEmailJobTests.<>c.<<Execute_WhenCalled_GetsTrnTokenSendsEmailAddsEventAndUpdatesDatabase>b__1_0>d.MoveNext() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/SendInternationalQtsAwardedEmailJobTests.cs:line 85
--- End of stack trace from previous location ---
   at TeachingRecordSystem.TestCommon.DbFixture.<>c__DisplayClass13_0.<<WithDbContextAsync>b__0>d.MoveNext() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 35
--- End of stack trace from previous location ---
   at TeachingRecordSystem.TestCommon.DbFixture.WithDbContextAsync[T](Func`2 action) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 29
   at TeachingRecordSystem.TestCommon.DbFixture.WithDbContextAsync[T](Func`2 action) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 29

Check failure on line 139 in TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs

View workflow job for this annotation

GitHub Actions / TeachingRecordSystem.Core.Tests test results

TeachingRecordSystem.Core.Tests.Jobs.SendQtsAwardedEmailJobTests ► Execute_WhenCalled_GetsTrnTokenSendsEmailAddsEventAndUpdatesDatabase

Failed test found in: TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/TestResults/_fv-az1198-760_2024-12-17_16_51_13.trx Error: System.InvalidOperationException : No service for type 'TeachingRecordSystem.Core.Services.Webhooks.WebhookMessageFactory' has been registered.
Raw output
System.InvalidOperationException : No service for type 'TeachingRecordSystem.Core.Services.Webhooks.WebhookMessageFactory' has been registered.
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   at TeachingRecordSystem.Core.DataStore.Postgres.TrsDbContext.AddEventAndBroadcastAsync(EventBase event) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.Core/DataStore/Postgres/TrsDbContext.cs:line 139
   at TeachingRecordSystem.Core.Jobs.SendQtsAwardedEmailJob.ExecuteAsync(Guid qtsAwardedEmailsJobId, Guid personId) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/src/TeachingRecordSystem.Core/Jobs/SendQtsAwardedEmailJob.cs:line 52
   at TeachingRecordSystem.Core.Tests.Jobs.SendQtsAwardedEmailJobTests.<>c.<<Execute_WhenCalled_GetsTrnTokenSendsEmailAddsEventAndUpdatesDatabase>b__1_0>d.MoveNext() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.Core.Tests/Jobs/SendQtsAwardedEmailJobTests.cs:line 85
--- End of stack trace from previous location ---
   at TeachingRecordSystem.TestCommon.DbFixture.<>c__DisplayClass13_0.<<WithDbContextAsync>b__0>d.MoveNext() in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 35
--- End of stack trace from previous location ---
   at TeachingRecordSystem.TestCommon.DbFixture.WithDbContextAsync[T](Func`2 action) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 29
   at TeachingRecordSystem.TestCommon.DbFixture.WithDbContextAsync[T](Func`2 action) in /home/runner/work/teaching-record-system/teaching-record-system/TeachingRecordSystem/tests/TeachingRecordSystem.TestCommon/DbFixture.cs:line 29
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public TrsDbContext CreateDbContext(string[] args)

var connectionString = configuration.GetPostgresConnectionString();

var optionsBuilder = new DbContextOptionsBuilder<TrsDbContext>();
TrsDbContext.ConfigureOptions(optionsBuilder, connectionString);

return new TrsDbContext(optionsBuilder.Options);
return TrsDbContext.Create(connectionString);
}
}
11 changes: 11 additions & 0 deletions TeachingRecordSystem/src/TeachingRecordSystem.Core/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -72,6 +74,15 @@ public static IHostApplicationBuilder AddHangfire(this IHostApplicationBuilder b
return builder;
}

public static IHostApplicationBuilder AddWebhookMessageFactory(this IHostApplicationBuilder builder)
{
builder.Services.AddSingleton<WebhookMessageFactory>();
builder.Services.AddSingleton<EventMapperRegistry>();
builder.Services.TryAddSingleton<PersonInfoCache>();

return builder;
}

public static void ConfigureSerilog(
this LoggerConfiguration config,
IHostEnvironment environment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
await _dbContext.AddEventAndBroadcastAsync(new EytsAwardedEmailSentEvent
{
EventId = Guid.NewGuid(),
EytsAwardedEmailsJobId = eytsAwardedEmailsJobId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
await _dbContext.AddEventAndBroadcastAsync(new InductionCompletedEmailSentEvent
{
EventId = Guid.NewGuid(),
InductionCompletedEmailsJobId = inductionCompletedEmailsJobId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
await _dbContext.AddEventAndBroadcastAsync(new InternationalQtsAwardedEmailSentEvent
{
EventId = Guid.NewGuid(),
InternationalQtsAwardedEmailsJobId = internationalQtsAwardedEmailsJobId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
await _dbContext.AddEventAndBroadcastAsync(new QtsAwardedEmailSentEvent
{
EventId = Guid.NewGuid(),
QtsAwardedEmailsJobId = qtsAwardedEmailsJobId,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MapperKey, MapperValue> _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<MapperKey, MapperValue> 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<MapperKey, MapperValue>();

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;
}
}
Original file line number Diff line number Diff line change
@@ -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<IEnumerable<WebhookMessage>> 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<WebhookMessage>();

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<object?> 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<object?> MapEventAsync(EventBase @event);
}

private class WrappedMapper<TEvent, TData>(IEventMapper<TEvent, TData> innerMapper) : IEventMapper
where TEvent : EventBase
where TData : IWebhookMessageData
{
public async Task<object?> MapEventAsync(EventBase @event) =>
await innerMapper.MapEventAsync((TEvent)@event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static IHostApplicationBuilder AddServiceDefaults(
builder.AddDatabase();
builder.AddHangfire();
builder.AddBackgroundWorkScheduler();
builder.AddWebhookMessageFactory();

builder.Services.AddHealthChecks().AddNpgSql(sp => sp.GetRequiredService<NpgsqlDataSource>());
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task<IActionResult> OnPostAsync()
out var createdEvent);

dbContext.Alerts.Add(alert);
dbContext.AddEvent(createdEvent);
await dbContext.AddEventAndBroadcastAsync(createdEvent);
await dbContext.SaveChangesAsync();

await JourneyInstance!.CompleteAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async Task<IActionResult> OnPostAsync()
Changes = AlertUpdatedEventChanges.EndDate
};

dbContext.AddEvent(updatedEvent);
await dbContext.AddEventAndBroadcastAsync(updatedEvent);

await dbContext.SaveChangesAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public async Task<IActionResult> OnPostAsync()
clock.UtcNow,
out var deletedEvent);

dbContext.AddEvent(deletedEvent);
await dbContext.AddEventAndBroadcastAsync(deletedEvent);
await dbContext.SaveChangesAsync();

await JourneyInstance!.CompleteAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<IActionResult> OnPostAsync()

if (updatedEvent is not null)
{
dbContext.AddEvent(updatedEvent);
await dbContext.AddEventAndBroadcastAsync(updatedEvent);
await dbContext.SaveChangesAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<IActionResult> OnPostAsync()

if (updatedEvent is not null)
{
dbContext.AddEvent(updatedEvent);
await dbContext.AddEventAndBroadcastAsync(updatedEvent);
await dbContext.SaveChangesAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task<IActionResult> OnPostAsync()

if (updatedEvent is not null)
{
dbContext.AddEvent(updatedEvent);
await dbContext.AddEventAndBroadcastAsync(updatedEvent);
await dbContext.SaveChangesAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task<IActionResult> OnPostAsync()

if (updatedEvent is not null)
{
dbContext.AddEvent(updatedEvent);
await dbContext.AddEventAndBroadcastAsync(updatedEvent);
await dbContext.SaveChangesAsync();
}

Expand Down
Loading

0 comments on commit 350b26c

Please sign in to comment.