diff --git a/docs/schema/V1/schema.verified.graphql b/docs/schema/V1/schema.verified.graphql index a0c84a248..1eb3d865f 100644 --- a/docs/schema/V1/schema.verified.graphql +++ b/docs/schema/V1/schema.verified.graphql @@ -132,8 +132,9 @@ type DialogByIdPayload { errors: [DialogByIdError!]! } -type DialogUpdatedPayload { +type DialogEventPayload { id: UUID! + type: DialogEventType! } type GuiAction { @@ -211,7 +212,7 @@ type SeenLog { } type Subscriptions @authorize(policy: "enduser") { - dialogUpdated(dialogId: UUID!): DialogUpdatedPayload! + dialogEvents(dialogId: UUID!): DialogEventPayload! } type Transmission { @@ -296,6 +297,11 @@ enum AttachmentUrlConsumer { API } +enum DialogEventType { + DIALOG_UPDATED + DIALOG_DELETED +} + enum DialogStatus { "The dialogue is considered new. Typically used for simple messages that do not require any interaction, or as an initial step for dialogues. This is the default." NEW @@ -355,4 +361,4 @@ scalar DateTime @specifiedBy(url: "https:\/\/www.graphql-scalars.com\/date-time" scalar URL @specifiedBy(url: "https:\/\/tools.ietf.org\/html\/rfc3986") -scalar UUID @specifiedBy(url: "https:\/\/tools.ietf.org\/html\/rfc4122") +scalar UUID @specifiedBy(url: "https:\/\/tools.ietf.org\/html\/rfc4122") \ No newline at end of file diff --git a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/ObjectTypes.cs b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/ObjectTypes.cs index faba0fe06..994db3121 100644 --- a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/ObjectTypes.cs +++ b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/ObjectTypes.cs @@ -201,7 +201,14 @@ public enum AttachmentUrlConsumer Api = 2 } -public sealed class DialogUpdatedPayload +public sealed class DialogEventPayload { public Guid Id { get; set; } + public DialogEventType Type { get; set; } +} + +public enum DialogEventType +{ + DialogUpdated = 1, + DialogDeleted = 2 } diff --git a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/Subscriptions.cs b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/Subscriptions.cs index 631063e70..9cd836902 100644 --- a/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/Subscriptions.cs +++ b/src/Digdir.Domain.Dialogporten.GraphQL/EndUser/DialogById/Subscriptions.cs @@ -10,11 +10,12 @@ namespace Digdir.Domain.Dialogporten.GraphQL.EndUser.DialogById; public sealed class Subscriptions { [Subscribe] - [Topic($"{Constants.DialogUpdatedTopic}{{{nameof(dialogId)}}}")] - public DialogUpdatedPayload DialogUpdated(Guid dialogId, - [EventMessage] Guid eventMessage) + [Topic($"{Constants.DialogEventsTopic}{{{nameof(dialogId)}}}")] + public DialogEventPayload DialogEvents(Guid dialogId, + [EventMessage] DialogEventPayload eventMessage) { + ArgumentNullException.ThrowIfNull(dialogId); ArgumentNullException.ThrowIfNull(eventMessage); - return new DialogUpdatedPayload { Id = dialogId }; + return eventMessage; } } diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/ConvertDomainEventsToOutboxMessagesInterceptor.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/ConvertDomainEventsToOutboxMessagesInterceptor.cs index 7bf891825..d1ec48d43 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/ConvertDomainEventsToOutboxMessagesInterceptor.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/DomainEvents/Outbox/ConvertDomainEventsToOutboxMessagesInterceptor.cs @@ -1,6 +1,8 @@ using Digdir.Domain.Dialogporten.Application.Common; using Digdir.Domain.Dialogporten.Domain.Dialogs.Events; +using Digdir.Domain.Dialogporten.Domain.Dialogs.Events.Activities; using Digdir.Domain.Dialogporten.Domain.Outboxes; +using Digdir.Domain.Dialogporten.Infrastructure.GraphQl; using Digdir.Library.Entity.Abstractions.Features.EventPublisher; using HotChocolate.Subscriptions; using Microsoft.EntityFrameworkCore.Diagnostics; @@ -72,8 +74,28 @@ public override async ValueTask SavedChangesAsync(SaveChangesCompletedEvent var task = domainEvent switch { DialogUpdatedDomainEvent dialogUpdatedDomainEvent => _topicEventSender.SendAsync( - $"{Constants.DialogUpdatedTopic}{dialogUpdatedDomainEvent.DialogId}", - dialogUpdatedDomainEvent.DialogId, + $"{Constants.DialogEventsTopic}{dialogUpdatedDomainEvent.DialogId}", + new DialogEventPayload + { + Id = dialogUpdatedDomainEvent.DialogId, + Type = DialogEventType.DialogUpdated + }, + cancellationToken), + DialogDeletedDomainEvent dialogDeletedDomainEvent => _topicEventSender.SendAsync( + $"{Constants.DialogEventsTopic}{dialogDeletedDomainEvent.DialogId}", + new DialogEventPayload + { + Id = dialogDeletedDomainEvent.DialogId, + Type = DialogEventType.DialogDeleted + }, + cancellationToken), + DialogActivityCreatedDomainEvent dialogActivityCreatedDomainEvent => _topicEventSender.SendAsync( + $"{Constants.DialogEventsTopic}{dialogActivityCreatedDomainEvent.DialogId}", + new DialogEventPayload + { + Id = dialogActivityCreatedDomainEvent.DialogId, + Type = DialogEventType.DialogUpdated + }, cancellationToken), _ => ValueTask.CompletedTask }; diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/GraphQL/DialogEventPayload.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/GraphQL/DialogEventPayload.cs new file mode 100644 index 000000000..32ba92f4a --- /dev/null +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/GraphQL/DialogEventPayload.cs @@ -0,0 +1,13 @@ +namespace Digdir.Domain.Dialogporten.Infrastructure.GraphQl; + +internal struct DialogEventPayload +{ + public Guid Id { get; set; } + public DialogEventType Type { get; set; } +} + +internal enum DialogEventType +{ + DialogUpdated = 1, + DialogDeleted = 2 +} diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/GraphQL/GraphQlSubscriptionConstants.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/GraphQL/GraphQlSubscriptionConstants.cs index 646f1e2de..779d7c5eb 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/GraphQL/GraphQlSubscriptionConstants.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/GraphQL/GraphQlSubscriptionConstants.cs @@ -3,5 +3,5 @@ namespace Digdir.Domain.Dialogporten.Infrastructure.GraphQl; public static class GraphQlSubscriptionConstants { public const string SubscriptionTopicPrefix = "graphql_subscriptions_"; - public const string DialogUpdatedTopic = "dialogUpdated/"; + public const string DialogEventsTopic = "dialogEvents/"; } diff --git a/tests/Digdir.Domain.Dialogporten.Architecture.Tests/InfrastructureArchitectureTests.cs b/tests/Digdir.Domain.Dialogporten.Architecture.Tests/InfrastructureArchitectureTests.cs index 5516b6a7b..4a6b0e824 100644 --- a/tests/Digdir.Domain.Dialogporten.Architecture.Tests/InfrastructureArchitectureTests.cs +++ b/tests/Digdir.Domain.Dialogporten.Architecture.Tests/InfrastructureArchitectureTests.cs @@ -15,7 +15,7 @@ public void All_Classes_In_Infrastructure_Should_Be_Internal() { nameof(InfrastructureAssemblyMarker), nameof(InfrastructureExtensions), - + // These classes are currently public, but should be internal, moved to another assembly, or deleted nameof(OutboxScheduler), nameof(IUpstreamServiceError)