Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add missing events to dialog subscription #1163

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/schema/V1/schema.verified.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ type DialogByIdPayload {
errors: [DialogByIdError!]!
}

type DialogUpdatedPayload {
type DialogEventPayload {
id: UUID!
type: DialogEventType!
}

type GuiAction {
Expand Down Expand Up @@ -211,7 +212,7 @@ type SeenLog {
}

type Subscriptions @authorize(policy: "enduser") {
dialogUpdated(dialogId: UUID!): DialogUpdatedPayload!
dialogEvents(dialogId: UUID!): DialogEventPayload!
}

type Transmission {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -72,8 +74,28 @@ public override async ValueTask<int> 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
},
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
cancellationToken),
_ => ValueTask.CompletedTask
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading