-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deletion of messages after sender and all recipients have been anonym…
…ized (#861) * feat: find orphaned messages * chore: remove empty EventHandlerService folder from the root folder * feat: add delete method MessagesRepository * feat: add IsOrphaned check * fix: IsAnonymized method * chore: revert changes because they break single responsibility rule * feat: add CheckForOrphanedMessages method * chore: remove unused using * refactor: IsOrphaned method to void * feat: add MessageOrphanedDomainEvent * chore: fix tests * chore: remove Domain Events * chore: revert code in ActualDeletionWorker * fix: remove Domain Event subscription * feat: add delete method to messages repository * refactor: make IsOrphaned bool * chore: revert tests * feat: add Delete Orhpaned Messages * feat: add IsMessageOrphaned expression * chore: remove unused usings * chore: remove unused methods * chore: remove blank line * refactor: remove unused parametar from command * test: improve test * test: add expression tests * chore: revert changes in csproj file * chore: move method to the bottom * chore: rename tests * fix: use logical && operator instead of bitwise & * refactor: IsMessageOrphaned method * feat: add MessageOrphaned external event type * chore: delete orphaned messages command * test: fix tests * feat: implement MessageOrphanedDomainEvent * chore: fix formatting * test: improve tests * chore: remove the creation of external event for orphaned messages * chore: remove expression tests * wip * fix: domain event * test: revert check for raised domain events * chore: fix formatting issue * test: improve tests * chore: remove leftover unused code & formatting * refactor: rename methods to match convention * refactor: delete message by Id to avoid unnecessary database roundtrip * chore: delete unused property from MessageOrphanedDomainEvent * fix: make MessageOrphanedDomainEvent deserializable * fix: seal ToString method in StronglyTypedId * refactor: rename some variables and methods * refactor: make IsOrphaned method private * refactor: update test name to match method name * test: add NotHaveADomainEvent extension method to EntityAssertions * test: simplify tests * refactor: move private method below public method * test: fix nullability problems --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Timo Notheisen <[email protected]>
- Loading branch information
1 parent
9896fed
commit 4e883dd
Showing
15 changed files
with
258 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
BuildingBlocks/src/UnitTestTools/FluentAssertions/Extensions/EntityExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
using Backbone.BuildingBlocks.Domain; | ||
using FluentAssertions; | ||
using Backbone.UnitTestTools.FluentAssertions.Assertions; | ||
|
||
namespace Backbone.UnitTestTools.FluentAssertions.Extensions; | ||
// ReSharper disable once CheckNamespace | ||
#pragma warning disable IDE0130 | ||
namespace FluentAssertions; | ||
#pragma warning restore IDE0130 | ||
|
||
public static class EntityExtensions | ||
{ | ||
public static EntityAssertions Should(this Entity instance) => new(instance); | ||
public static EntityAssertions Should(this Entity? instance) => new(instance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...es.Application/DomainEvents/Incoming/MessageOrphaned/MessageOrphanedDomainEventHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; | ||
using Backbone.Modules.Messages.Application.Infrastructure.Persistence.Repository; | ||
using Backbone.Modules.Messages.Domain.DomainEvents.Outgoing; | ||
using MessageId = Backbone.Modules.Messages.Domain.Ids.MessageId; | ||
|
||
namespace Backbone.Modules.Messages.Application.DomainEvents.Incoming.MessageOrphaned; | ||
|
||
public class MessageOrphanedDomainEventHandler : IDomainEventHandler<MessageOrphanedDomainEvent> | ||
{ | ||
private readonly IMessagesRepository _messagesRepository; | ||
|
||
public MessageOrphanedDomainEventHandler(IMessagesRepository messagesRepository) | ||
{ | ||
_messagesRepository = messagesRepository; | ||
} | ||
|
||
public async Task Handle(MessageOrphanedDomainEvent @event) | ||
{ | ||
var messageId = MessageId.Parse(@event.MessageId); | ||
await _messagesRepository.Delete(messageId, CancellationToken.None); | ||
} | ||
} |
16 changes: 14 additions & 2 deletions
16
Modules/Messages/src/Messages.Application/Extensions/IEventBusExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.EventBus; | ||
using Backbone.Modules.Messages.Application.DomainEvents.Incoming.MessageOrphaned; | ||
using Backbone.Modules.Messages.Application.DomainEvents.Incoming.RelationshipStatusChanged; | ||
using Backbone.Modules.Messages.Domain.DomainEvents.Incoming; | ||
using Backbone.Modules.Messages.Domain.DomainEvents.Outgoing; | ||
|
||
namespace Backbone.Modules.Messages.Application.Extensions; | ||
|
||
public static class IEventBusExtensions | ||
{ | ||
public static IEventBus AddMessagesDomainEventSubscriptions(this IEventBus eventBus) | ||
public static void AddMessagesDomainEventSubscriptions(this IEventBus eventBus) | ||
{ | ||
SubscribeToMessagesEvents(eventBus); | ||
SubscribeToRelationshipsEvents(eventBus); | ||
} | ||
|
||
private static void SubscribeToMessagesEvents(IEventBus eventBus) | ||
{ | ||
eventBus.Subscribe<MessageOrphanedDomainEvent, MessageOrphanedDomainEventHandler>(); | ||
} | ||
|
||
private static void SubscribeToRelationshipsEvents(IEventBus eventBus) | ||
{ | ||
eventBus.Subscribe<RelationshipStatusChangedDomainEvent, RelationshipStatusChangedDomainEventHandler>(); | ||
return eventBus; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
Modules/Messages/src/Messages.Domain/DomainEvents/Outgoing/MessageOrphanedDomainEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Backbone.BuildingBlocks.Domain.Events; | ||
using Backbone.Modules.Messages.Domain.Entities; | ||
|
||
namespace Backbone.Modules.Messages.Domain.DomainEvents.Outgoing; | ||
|
||
public class MessageOrphanedDomainEvent : DomainEvent | ||
{ | ||
/** | ||
* This constructor is used by the deserializer. | ||
*/ | ||
public MessageOrphanedDomainEvent() | ||
{ | ||
MessageId = null!; | ||
} | ||
|
||
public MessageOrphanedDomainEvent(Message message) : base($"{message.Id}/MessageOrphaned") | ||
{ | ||
MessageId = message.Id; | ||
} | ||
|
||
public string MessageId { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.