From 04272baf3d28cfbdf1dd0e088b2be29c5167becd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Sun, 18 Feb 2024 16:51:26 +0100 Subject: [PATCH 1/4] Use data from events --- .../DialogActivityEventToAltinnForwarder.cs | 47 +++----- .../DialogElementEventToAltinnForwarder.cs | 106 +++++++++--------- .../Events/DialogEventToAltinnForwarder.cs | 55 +++++---- .../DomainEventToAltinnForwarderBase.cs | 15 +-- .../Entities/Activities/DialogActivity.cs | 5 +- .../Dialogs/Entities/DialogEntity.cs | 6 +- .../Entities/Elements/DialogElement.cs | 16 ++- .../DialogActivityCreatedDomainEvent.cs | 12 +- .../Events/DialogCreatedDomainEvent.cs | 2 +- .../DialogElementCreatedDomainEvent.cs | 8 +- .../DialogElementDeletedDomainEvent.cs | 4 +- .../DialogElementUpdatedDomainEvent.cs | 8 +- .../Dialogs/Events/DialogSeenDomainEvent.cs | 2 +- .../Events/DialogUpdatedDomainEvent.cs | 2 +- 14 files changed, 158 insertions(+), 130 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs index e48d98761..2133f8aae 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs @@ -10,62 +10,51 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events; internal sealed class DialogActivityEventToAltinnForwarder : DomainEventToAltinnForwarderBase, INotificationHandler { - public DialogActivityEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, IOptions settings) - : base(cloudEventBus, db, settings) { } + public DialogActivityEventToAltinnForwarder(ICloudEventBus cloudEventBus, IOptions settings) + : base(cloudEventBus, settings) { } public async Task Handle(DialogActivityCreatedDomainEvent domainEvent, CancellationToken cancellationToken) { - var dialogActivity = await Db.DialogActivities - .Include(e => e.Dialog) - .Include(e => e.DialogElement) - .Include(e => e.RelatedActivity) - .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == domainEvent.DialogActivityId, cancellationToken) - ?? throw new KeyNotFoundException($"DialogActivity with id {domainEvent.DialogActivityId} not found"); - var cloudEvent = new CloudEvent { Id = domainEvent.EventId, - Type = CloudEventTypes.Get(dialogActivity.TypeId), + Type = CloudEventTypes.Get(domainEvent.TypeId), Time = domainEvent.OccuredAt, - Resource = dialogActivity.Dialog.ServiceResource, - ResourceInstance = dialogActivity.Dialog.Id.ToString(), - Subject = dialogActivity.Dialog.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{dialogActivity.Dialog.Id}/activities/{dialogActivity.Id}", - Data = GetCloudEventData(dialogActivity) + Resource = domainEvent.ServiceResource, + ResourceInstance = domainEvent.DialogId.ToString(), + Subject = domainEvent.Party, + Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}/activities/{domainEvent.ActivityId}", + Data = GetCloudEventData(domainEvent) }; await CloudEventBus.Publish(cloudEvent, cancellationToken); } - private static Dictionary GetCloudEventData(DialogActivity dialogActivity) + private static Dictionary GetCloudEventData(DialogActivityCreatedDomainEvent domainEvent) { var data = new Dictionary { - ["activityId"] = dialogActivity.Id.ToString(), + ["activityId"] = domainEvent.ActivityId.ToString(), }; - if (dialogActivity.ExtendedType is not null) + if (domainEvent.ExtendedType is not null) { - data["extendedActivityType"] = dialogActivity.ExtendedType.ToString(); + data["extendedActivityType"] = domainEvent.ExtendedType; } - if (dialogActivity.RelatedActivity is not null) + if (domainEvent.RelatedActivityId is not null) { - data["extendedActivityType"] = dialogActivity.RelatedActivity.Id.ToString()!; + data["relatedActivityId"] = domainEvent.RelatedActivityId.ToString()!; } - if (dialogActivity.DialogElement is null) return data; - - data["dialogElementId"] = dialogActivity.DialogElement.Id.ToString(); - if (dialogActivity.DialogElement.Type is not null) + if (domainEvent.DialogElementId is not null) { - data["dialogElementType"] = dialogActivity.DialogElement.Type.ToString(); + data["dialogElementId"] = domainEvent.DialogElementId.ToString()!; } - if (dialogActivity.DialogElement.RelatedDialogElement is not null) + if (domainEvent.DialogElementType is not null) { - data["relatedDialogElementId"] = dialogActivity.DialogElement.RelatedDialogElement.Id.ToString()!; + data["dialogElementType"] = domainEvent.DialogElementType.ToString(); } return data; diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs index 5ce73b891..709cc3125 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs @@ -4,7 +4,9 @@ using Digdir.Library.Entity.Abstractions.Features.EventPublisher; using MediatR; using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Options; +using OneOf; namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events; @@ -13,29 +15,43 @@ internal sealed class DialogElementEventToAltinnForwarder : DomainEventToAltinnF INotificationHandler, INotificationHandler { - public DialogElementEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, IOptions settings) - : base(cloudEventBus, db, settings) - { - } + public DialogElementEventToAltinnForwarder(ICloudEventBus cloudEventBus, IOptions settings) + : base(cloudEventBus, settings) { } public async Task Handle(DialogElementUpdatedDomainEvent domainEvent, CancellationToken cancellationToken) { - var dialogElement = await GetDialogElement(domainEvent.DialogElementId, cancellationToken); - var cloudEvent = CreateCloudEvent(dialogElement, domainEvent); - await CloudEventBus.Publish(cloudEvent, cancellationToken); - } + var data = new Dictionary + { + ["dialogElementId"] = domainEvent.DialogElementId.ToString() + }; + + if (domainEvent.RelatedDialogElementId is not null) + { + data["relatedDialogElementId"] = domainEvent.RelatedDialogElementId; + } + + if (domainEvent.Type is not null) + { + data["dialogElementType"] = domainEvent.Type; + } + + var cloudEvent = new CloudEvent + { + Id = domainEvent.EventId, + Type = CloudEventTypes.Get(domainEvent), + Time = domainEvent.OccuredAt, + Resource = domainEvent.ServiceResource, + ResourceInstance = domainEvent.DialogId.ToString(), + Subject = domainEvent.Party, + Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", + Data = data + }; - public async Task Handle(DialogElementCreatedDomainEvent domainEvent, CancellationToken cancellationToken) - { - var dialogElement = await GetDialogElement(domainEvent.DialogElementId, cancellationToken); - var cloudEvent = CreateCloudEvent(dialogElement, domainEvent); await CloudEventBus.Publish(cloudEvent, cancellationToken); } - public async Task Handle(DialogElementDeletedDomainEvent domainEvent, CancellationToken cancellationToken) + public async Task Handle(DialogElementCreatedDomainEvent domainEvent, CancellationToken cancellationToken) { - var dialog = await GetDialog(domainEvent.DialogId, cancellationToken); - var data = new Dictionary { ["dialogElementId"] = domainEvent.DialogElementId.ToString() @@ -43,12 +59,12 @@ public async Task Handle(DialogElementDeletedDomainEvent domainEvent, Cancellati if (domainEvent.RelatedDialogElementId is not null) { - data["relatedDialogElementId"] = domainEvent.RelatedDialogElementId.Value.ToString(); + data["relatedDialogElementId"] = domainEvent.RelatedDialogElementId; } if (domainEvent.Type is not null) { - data["dialogElementType"] = domainEvent.Type.ToString(); + data["dialogElementType"] = domainEvent.Type; } var cloudEvent = new CloudEvent @@ -56,57 +72,45 @@ public async Task Handle(DialogElementDeletedDomainEvent domainEvent, Cancellati Id = domainEvent.EventId, Type = CloudEventTypes.Get(domainEvent), Time = domainEvent.OccuredAt, - Resource = dialog.ServiceResource, - ResourceInstance = dialog.Id.ToString(), - Subject = dialog.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{dialog.Id}/elements/{domainEvent.DialogElementId}", + Resource = domainEvent.ServiceResource, + ResourceInstance = domainEvent.DialogId.ToString(), + Subject = domainEvent.Party, + Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", Data = data }; await CloudEventBus.Publish(cloudEvent, cancellationToken); } - private CloudEvent CreateCloudEvent(DialogElement dialogElement, IDomainEvent domainEvent) => new() - { - Id = domainEvent.EventId, - Type = CloudEventTypes.Get(domainEvent), - Time = domainEvent.OccuredAt, - Resource = dialogElement.Dialog.ServiceResource, - ResourceInstance = dialogElement.Dialog.Id.ToString(), - Subject = dialogElement.Dialog.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{dialogElement.Dialog.Id}/elements/{dialogElement.Id}", - Data = GetCloudEventData(dialogElement) - }; - - private static Dictionary GetCloudEventData(DialogElement dialogElement) + public async Task Handle(DialogElementDeletedDomainEvent domainEvent, CancellationToken cancellationToken) { var data = new Dictionary { - ["dialogElementId"] = dialogElement.Id.ToString() + ["dialogElementId"] = domainEvent.DialogElementId.ToString() }; - if (dialogElement.RelatedDialogElement is not null) + if (domainEvent.RelatedDialogElementId is not null) { - data["relatedDialogElementId"] = dialogElement.RelatedDialogElement.Id.ToString(); + data["relatedDialogElementId"] = domainEvent.RelatedDialogElementId; } - if (dialogElement.Type is not null) + if (domainEvent.Type is not null) { - data["dialogElementType"] = dialogElement.Type.ToString(); + data["dialogElementType"] = domainEvent.Type; } - return data; - } + var cloudEvent = new CloudEvent + { + Id = domainEvent.EventId, + Type = CloudEventTypes.Get(domainEvent), + Time = domainEvent.OccuredAt, + Resource = domainEvent.ServiceResource, + ResourceInstance = domainEvent.DialogId.ToString(), + Subject = domainEvent.Party, + Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", + Data = data + }; - private async Task GetDialogElement(Guid dialogElementId, CancellationToken cancellationToken) - { - var dialogElement = await Db.DialogElements - .Include(e => e.Dialog) - .Include(e => e.RelatedDialogElement) - .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == dialogElementId, cancellationToken) - ?? throw new KeyNotFoundException($"DialogElement with id {dialogElementId} not found"); - - return dialogElement; + await CloudEventBus.Publish(cloudEvent, cancellationToken); } } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs index 036dd0449..e6ad7fb10 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs @@ -13,28 +13,53 @@ internal sealed class DialogEventToAltinnForwarder : DomainEventToAltinnForwarde INotificationHandler, INotificationHandler { - public DialogEventToAltinnForwarder(ICloudEventBus cloudEventBus, IDialogDbContext db, - IOptions settings) - : base(cloudEventBus, db, settings) { } + public DialogEventToAltinnForwarder(ICloudEventBus cloudEventBus, IOptions settings) + : base(cloudEventBus, settings) { } public async Task Handle(DialogCreatedDomainEvent domainEvent, CancellationToken cancellationToken) { - var dialog = await GetDialog(domainEvent.DialogId, cancellationToken); - var cloudEvent = CreateCloudEvent(domainEvent, dialog); + var cloudEvent = new CloudEvent + { + Id = domainEvent.EventId, + Type = CloudEventTypes.Get(domainEvent), + Time = domainEvent.OccuredAt, + Resource = domainEvent.ServiceResource, + ResourceInstance = domainEvent.DialogId.ToString(), + Subject = domainEvent.Party, + Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}" + }; await CloudEventBus.Publish(cloudEvent, cancellationToken); } public async Task Handle(DialogUpdatedDomainEvent domainEvent, CancellationToken cancellationToken) { - var dialog = await GetDialog(domainEvent.DialogId, cancellationToken); - var cloudEvent = CreateCloudEvent(domainEvent, dialog); + var cloudEvent = new CloudEvent + { + Id = domainEvent.EventId, + Type = CloudEventTypes.Get(domainEvent), + Time = domainEvent.OccuredAt, + Resource = domainEvent.ServiceResource, + ResourceInstance = domainEvent.DialogId.ToString(), + Subject = domainEvent.Party, + Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}" + }; + await CloudEventBus.Publish(cloudEvent, cancellationToken); } public async Task Handle(DialogSeenDomainEvent domainEvent, CancellationToken cancellationToken) { - var dialog = await GetDialog(domainEvent.DialogId, cancellationToken); - var cloudEvent = CreateCloudEvent(domainEvent, dialog); + var cloudEvent = new CloudEvent + { + Id = domainEvent.EventId, + Type = CloudEventTypes.Get(domainEvent), + Time = domainEvent.OccuredAt, + Resource = domainEvent.ServiceResource, + ResourceInstance = domainEvent.DialogId.ToString(), + Subject = domainEvent.Party, + Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}" + }; + await CloudEventBus.Publish(cloudEvent, cancellationToken); } @@ -53,16 +78,4 @@ public async Task Handle(DialogDeletedDomainEvent domainEvent, CancellationToken await CloudEventBus.Publish(cloudEvent, cancellationToken); } - - private CloudEvent CreateCloudEvent(IDomainEvent domainEvent, DialogEntity dialog, Dictionary? data = null) => new() - { - Id = domainEvent.EventId, - Type = CloudEventTypes.Get(domainEvent), - Time = domainEvent.OccuredAt, - Resource = dialog.ServiceResource, - ResourceInstance = dialog.Id.ToString(), - Subject = dialog.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{dialog.Id}", - Data = data - }; } diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs index 29cc0ea40..8401fe319 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs @@ -8,26 +8,13 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events; internal class DomainEventToAltinnForwarderBase { protected readonly ICloudEventBus CloudEventBus; - protected readonly IDialogDbContext Db; private readonly DialogportenSettings _dialogportenSettings; - protected DomainEventToAltinnForwarderBase(ICloudEventBus cloudEventBus, IDialogDbContext db, IOptions settings) + protected DomainEventToAltinnForwarderBase(ICloudEventBus cloudEventBus, IOptions settings) { CloudEventBus = cloudEventBus ?? throw new ArgumentNullException(nameof(cloudEventBus)); - Db = db ?? throw new ArgumentNullException(nameof(db)); _dialogportenSettings = settings.Value.Dialogporten ?? throw new ArgumentNullException(nameof(settings)); } protected string DialogportenBaseUrl() => _dialogportenSettings.BaseUri.ToString(); - - protected async Task GetDialog(Guid dialogId, CancellationToken cancellationToken) - { - var dialog = await Db.Dialogs - .IgnoreQueryFilters() - .AsNoTracking() - .FirstOrDefaultAsync(x => x.Id == dialogId, cancellationToken) - ?? throw new KeyNotFoundException($"Dialog with id {dialogId} not found"); - - return dialog; - } } diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivity.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivity.cs index 5e1cde17c..21dd90b00 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivity.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Activities/DialogActivity.cs @@ -38,7 +38,10 @@ public class DialogActivity : IImmutableEntity, IAggregateCreatedHandler, IEvent public void OnCreate(AggregateNode self, DateTimeOffset utcNow) { - _domainEvents.Add(new DialogActivityCreatedDomainEvent(DialogId, Id)); + _domainEvents.Add(new DialogActivityCreatedDomainEvent( + DialogId, Id, TypeId, Dialog.Party, + Dialog.ServiceResource, ExtendedType, + RelatedActivityId, DialogElementId, DialogElement?.Type)); } private readonly List _domainEvents = []; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs index 3aaec1f3c..f0b6e4c8a 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/DialogEntity.cs @@ -69,7 +69,7 @@ public void SoftDelete() public void OnCreate(AggregateNode self, DateTimeOffset utcNow) { - _domainEvents.Add(new DialogCreatedDomainEvent(Id)); + _domainEvents.Add(new DialogCreatedDomainEvent(Id, ServiceResource, Party)); } public void OnUpdate(AggregateNode self, DateTimeOffset utcNow) @@ -82,7 +82,7 @@ and not AggregateNode if (shouldProduceEvent) { - _domainEvents.Add(new DialogUpdatedDomainEvent(Id)); + _domainEvents.Add(new DialogUpdatedDomainEvent(Id, ServiceResource, Party)); } } @@ -124,7 +124,7 @@ public void UpdateSeenAt(string seenByEndUserId, string? seenByEndUserName) TypeId = DialogActivityType.Values.Seen }); - _domainEvents.Add(new DialogSeenDomainEvent(Id)); + _domainEvents.Add(new DialogSeenDomainEvent(Id, ServiceResource, Party)); } private readonly List _domainEvents = []; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Elements/DialogElement.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Elements/DialogElement.cs index bf37fec40..8bdaaa7f0 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Elements/DialogElement.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Entities/Elements/DialogElement.cs @@ -35,22 +35,30 @@ public class DialogElement : IEntity, IAggregateChangedHandler, IEventPublisher public void OnCreate(AggregateNode self, DateTimeOffset utcNow) { - _domainEvents.Add(new DialogElementCreatedDomainEvent(DialogId, Id)); + _domainEvents.Add(new DialogElementCreatedDomainEvent( + DialogId, Id, Dialog.ServiceResource, Dialog.Party, + RelatedDialogElementId?.ToString(), Type?.ToString())); } public void OnUpdate(AggregateNode self, DateTimeOffset utcNow) { - _domainEvents.Add(new DialogElementUpdatedDomainEvent(DialogId, Id)); + _domainEvents.Add(new DialogElementUpdatedDomainEvent( + DialogId, Id, Dialog.ServiceResource, Dialog.Party, + RelatedDialogElementId?.ToString(), Type?.ToString())); } public void OnDelete(AggregateNode self, DateTimeOffset utcNow) { - _domainEvents.Add(new DialogElementDeletedDomainEvent(DialogId, Id, RelatedDialogElementId, Type)); + _domainEvents.Add(new DialogElementDeletedDomainEvent( + DialogId, Id, Dialog.ServiceResource, + Dialog.Party, RelatedDialogElementId, Type)); } public void SoftDelete() { - _domainEvents.Add(new DialogElementDeletedDomainEvent(DialogId, Id, RelatedDialogElementId, Type)); + _domainEvents.Add(new DialogElementDeletedDomainEvent( + DialogId, Id, Dialog.ServiceResource, + Dialog.Party, RelatedDialogElementId, Type)); } private readonly List _domainEvents = []; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/Activities/DialogActivityCreatedDomainEvent.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/Activities/DialogActivityCreatedDomainEvent.cs index f20ecfb27..ea4791c92 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/Activities/DialogActivityCreatedDomainEvent.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/Activities/DialogActivityCreatedDomainEvent.cs @@ -1,5 +1,15 @@ using Digdir.Domain.Dialogporten.Domain.Common; +using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Events.Activities; -public sealed record DialogActivityCreatedDomainEvent(Guid DialogId, Guid DialogActivityId) : DomainEvent; +public sealed record DialogActivityCreatedDomainEvent( + Guid DialogId, + Guid ActivityId, + DialogActivityType.Values TypeId, + string Party, + string ServiceResource, + Uri? ExtendedType, + Guid? RelatedActivityId, + Guid? DialogElementId, + Uri? DialogElementType) : DomainEvent; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogCreatedDomainEvent.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogCreatedDomainEvent.cs index 1cdddfaa6..06483b28c 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogCreatedDomainEvent.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogCreatedDomainEvent.cs @@ -2,4 +2,4 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Events; -public sealed record DialogCreatedDomainEvent(Guid DialogId) : DomainEvent; +public sealed record DialogCreatedDomainEvent(Guid DialogId, string ServiceResource, string Party) : DomainEvent; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementCreatedDomainEvent.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementCreatedDomainEvent.cs index a2b873921..0a9edee0d 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementCreatedDomainEvent.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementCreatedDomainEvent.cs @@ -2,4 +2,10 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Events.DialogElements; -public sealed record DialogElementCreatedDomainEvent(Guid DialogId, Guid DialogElementId) : DomainEvent; \ No newline at end of file +public sealed record DialogElementCreatedDomainEvent( + Guid DialogId, + Guid DialogElementId, + string ServiceResource, + string Party, + string? RelatedDialogElementId, + string? Type) : DomainEvent; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementDeletedDomainEvent.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementDeletedDomainEvent.cs index d2beb1a61..386fb75aa 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementDeletedDomainEvent.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementDeletedDomainEvent.cs @@ -5,6 +5,8 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Events.DialogElements; public sealed record DialogElementDeletedDomainEvent( Guid DialogId, Guid DialogElementId, + string ServiceResource, + string Party, Guid? RelatedDialogElementId, Uri? Type) : - DomainEvent; \ No newline at end of file + DomainEvent; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementUpdatedDomainEvent.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementUpdatedDomainEvent.cs index 80515bc50..38d5bc5bc 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementUpdatedDomainEvent.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogElements/DialogElementUpdatedDomainEvent.cs @@ -2,4 +2,10 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Events.DialogElements; -public sealed record DialogElementUpdatedDomainEvent(Guid DialogId, Guid DialogElementId) : DomainEvent; \ No newline at end of file +public sealed record DialogElementUpdatedDomainEvent( + Guid DialogId, + Guid DialogElementId, + string ServiceResource, + string Party, + string? RelatedDialogElementId, + string? Type) : DomainEvent; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogSeenDomainEvent.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogSeenDomainEvent.cs index 1a09da28a..cb4597d6c 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogSeenDomainEvent.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogSeenDomainEvent.cs @@ -2,4 +2,4 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Events; -public sealed record DialogSeenDomainEvent(Guid DialogId) : DomainEvent; +public sealed record DialogSeenDomainEvent(Guid DialogId, string ServiceResource, string Party) : DomainEvent; diff --git a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogUpdatedDomainEvent.cs b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogUpdatedDomainEvent.cs index 5c07398ef..662fe2d5d 100644 --- a/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogUpdatedDomainEvent.cs +++ b/src/Digdir.Domain.Dialogporten.Domain/Dialogs/Events/DialogUpdatedDomainEvent.cs @@ -2,4 +2,4 @@ namespace Digdir.Domain.Dialogporten.Domain.Dialogs.Events; -public sealed record DialogUpdatedDomainEvent(Guid DialogId) : DomainEvent; +public sealed record DialogUpdatedDomainEvent(Guid DialogId, string ServiceResource, string Party) : DomainEvent; From 83c5b6f6959e0c88043b74b768cd72eb4fec4686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Sun, 18 Feb 2024 16:55:58 +0100 Subject: [PATCH 2/4] Remove unused usings --- .../V1/Common/Events/DialogActivityEventToAltinnForwarder.cs | 2 -- .../V1/Common/Events/DialogElementEventToAltinnForwarder.cs | 5 ----- .../V1/Common/Events/DialogEventToAltinnForwarder.cs | 2 -- .../V1/Common/Events/DomainEventToAltinnForwarderBase.cs | 2 -- 4 files changed, 11 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs index 2133f8aae..61994e218 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs @@ -1,8 +1,6 @@ using Digdir.Domain.Dialogporten.Application.Externals; -using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Activities; using Digdir.Domain.Dialogporten.Domain.Dialogs.Events.Activities; using MediatR; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events; diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs index 709cc3125..a72e04346 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs @@ -1,12 +1,7 @@ using Digdir.Domain.Dialogporten.Application.Externals; -using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities.Elements; using Digdir.Domain.Dialogporten.Domain.Dialogs.Events.DialogElements; -using Digdir.Library.Entity.Abstractions.Features.EventPublisher; using MediatR; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Options; -using OneOf; namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events; diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs index e6ad7fb10..9c1ad2e62 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs @@ -1,7 +1,5 @@ using Digdir.Domain.Dialogporten.Application.Externals; -using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; using Digdir.Domain.Dialogporten.Domain.Dialogs.Events; -using Digdir.Library.Entity.Abstractions.Features.EventPublisher; using MediatR; using Microsoft.Extensions.Options; diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs index 8401fe319..2e48b28a3 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs @@ -1,6 +1,4 @@ using Digdir.Domain.Dialogporten.Application.Externals; -using Digdir.Domain.Dialogporten.Domain.Dialogs.Entities; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; namespace Digdir.Domain.Dialogporten.Application.Features.V1.Common.Events; From 6237284b25b64d0ca494165584d6e22909c1cdf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Sun, 18 Feb 2024 17:07:33 +0100 Subject: [PATCH 3/4] Move api path to SourceBaseUri --- .../Common/Events/DialogActivityEventToAltinnForwarder.cs | 4 ++-- .../Common/Events/DialogElementEventToAltinnForwarder.cs | 6 +++--- .../V1/Common/Events/DialogEventToAltinnForwarder.cs | 8 ++++---- .../V1/Common/Events/DomainEventToAltinnForwarderBase.cs | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs index 61994e218..f342ae6a6 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogActivityEventToAltinnForwarder.cs @@ -21,7 +21,7 @@ public async Task Handle(DialogActivityCreatedDomainEvent domainEvent, Cancellat Resource = domainEvent.ServiceResource, ResourceInstance = domainEvent.DialogId.ToString(), Subject = domainEvent.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}/activities/{domainEvent.ActivityId}", + Source = $"{SourceBaseUrl()}{domainEvent.DialogId}/activities/{domainEvent.ActivityId}", Data = GetCloudEventData(domainEvent) }; @@ -37,7 +37,7 @@ private static Dictionary GetCloudEventData(DialogActivityCreate if (domainEvent.ExtendedType is not null) { - data["extendedActivityType"] = domainEvent.ExtendedType; + data["extendedActivityType"] = domainEvent.ExtendedType.ToString(); } if (domainEvent.RelatedActivityId is not null) diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs index a72e04346..0a9ac6060 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogElementEventToAltinnForwarder.cs @@ -38,7 +38,7 @@ public async Task Handle(DialogElementUpdatedDomainEvent domainEvent, Cancellati Resource = domainEvent.ServiceResource, ResourceInstance = domainEvent.DialogId.ToString(), Subject = domainEvent.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", + Source = $"{SourceBaseUrl()}{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", Data = data }; @@ -70,7 +70,7 @@ public async Task Handle(DialogElementCreatedDomainEvent domainEvent, Cancellati Resource = domainEvent.ServiceResource, ResourceInstance = domainEvent.DialogId.ToString(), Subject = domainEvent.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", + Source = $"{SourceBaseUrl()}{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", Data = data }; @@ -102,7 +102,7 @@ public async Task Handle(DialogElementDeletedDomainEvent domainEvent, Cancellati Resource = domainEvent.ServiceResource, ResourceInstance = domainEvent.DialogId.ToString(), Subject = domainEvent.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", + Source = $"{SourceBaseUrl()}{domainEvent.DialogId}/elements/{domainEvent.DialogElementId}", Data = data }; diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs index 9c1ad2e62..40684226d 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DialogEventToAltinnForwarder.cs @@ -24,7 +24,7 @@ public async Task Handle(DialogCreatedDomainEvent domainEvent, CancellationToken Resource = domainEvent.ServiceResource, ResourceInstance = domainEvent.DialogId.ToString(), Subject = domainEvent.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}" + Source = $"{SourceBaseUrl()}{domainEvent.DialogId}" }; await CloudEventBus.Publish(cloudEvent, cancellationToken); } @@ -39,7 +39,7 @@ public async Task Handle(DialogUpdatedDomainEvent domainEvent, CancellationToken Resource = domainEvent.ServiceResource, ResourceInstance = domainEvent.DialogId.ToString(), Subject = domainEvent.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}" + Source = $"{SourceBaseUrl()}{domainEvent.DialogId}" }; await CloudEventBus.Publish(cloudEvent, cancellationToken); @@ -55,7 +55,7 @@ public async Task Handle(DialogSeenDomainEvent domainEvent, CancellationToken ca Resource = domainEvent.ServiceResource, ResourceInstance = domainEvent.DialogId.ToString(), Subject = domainEvent.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}" + Source = $"{SourceBaseUrl()}{domainEvent.DialogId}" }; await CloudEventBus.Publish(cloudEvent, cancellationToken); @@ -71,7 +71,7 @@ public async Task Handle(DialogDeletedDomainEvent domainEvent, CancellationToken Resource = domainEvent.ServiceResource, ResourceInstance = domainEvent.DialogId.ToString(), Subject = domainEvent.Party, - Source = $"{DialogportenBaseUrl()}/api/v1/enduser/dialogs/{domainEvent.DialogId}" + Source = $"{SourceBaseUrl()}{domainEvent.DialogId}" }; await CloudEventBus.Publish(cloudEvent, cancellationToken); diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs index 2e48b28a3..59ca3671c 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs @@ -14,5 +14,6 @@ protected DomainEventToAltinnForwarderBase(ICloudEventBus cloudEventBus, IOption _dialogportenSettings = settings.Value.Dialogporten ?? throw new ArgumentNullException(nameof(settings)); } - protected string DialogportenBaseUrl() => _dialogportenSettings.BaseUri.ToString(); + internal string SourceBaseUrl() => + $"{_dialogportenSettings.BaseUri.ToString()}/api/v1/enduser/dialogs/"; } From eb4c021050ad2d57881aa7450b4eadb95f3a858b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20J=C3=B8rgen=20Skogstad?= Date: Sun, 18 Feb 2024 22:08:23 +0100 Subject: [PATCH 4/4] Simplify string interpolation --- .../V1/Common/Events/DomainEventToAltinnForwarderBase.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs index 59ca3671c..18cfd9ff7 100644 --- a/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs +++ b/src/Digdir.Domain.Dialogporten.Application/Features/V1/Common/Events/DomainEventToAltinnForwarderBase.cs @@ -14,6 +14,6 @@ protected DomainEventToAltinnForwarderBase(ICloudEventBus cloudEventBus, IOption _dialogportenSettings = settings.Value.Dialogporten ?? throw new ArgumentNullException(nameof(settings)); } - internal string SourceBaseUrl() => - $"{_dialogportenSettings.BaseUri.ToString()}/api/v1/enduser/dialogs/"; + internal string SourceBaseUrl() => + $"{_dialogportenSettings.BaseUri}/api/v1/enduser/dialogs/"; }