-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#87) add events with handlers for creating and deleting organizers
- Loading branch information
Showing
13 changed files
with
148 additions
and
8 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
27 changes: 27 additions & 0 deletions
27
...vices.Organizations.Application/Events/External/Handlers/OrganizerRightsGrantedHandler.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,27 @@ | ||
using Convey.CQRS.Events; | ||
using MiniSpace.Services.Organizations.Application.Exceptions; | ||
using MiniSpace.Services.Organizations.Core.Entities; | ||
using MiniSpace.Services.Organizations.Core.Repositories; | ||
|
||
namespace MiniSpace.Services.Organizations.Application.Events.External.Handlers | ||
{ | ||
public class OrganizerRightsGrantedHandler : IEventHandler<OrganizerRightsGranted> | ||
{ | ||
private readonly IOrganizerRepository _organizerRepository; | ||
|
||
public OrganizerRightsGrantedHandler(IOrganizerRepository organizerRepository) | ||
{ | ||
_organizerRepository = organizerRepository; | ||
} | ||
|
||
public async Task HandleAsync(OrganizerRightsGranted @event, CancellationToken cancellationToken) | ||
{ | ||
if (await _organizerRepository.ExistsAsync(@event.UserId)) | ||
{ | ||
throw new OrganizerAlreadyAddedException(@event.UserId); | ||
} | ||
|
||
await _organizerRepository.AddAsync(new Organizer(@event.UserId)); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...vices.Organizations.Application/Events/External/Handlers/OrganizerRightsRevokedHandler.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,36 @@ | ||
using Convey.CQRS.Events; | ||
using MiniSpace.Services.Organizations.Application.Exceptions; | ||
using MiniSpace.Services.Organizations.Core.Repositories; | ||
|
||
namespace MiniSpace.Services.Organizations.Application.Events.External.Handlers | ||
{ | ||
public class OrganizerRightsRevokedHandler : IEventHandler<OrganizerRightsRevoked> | ||
{ | ||
private readonly IOrganizerRepository _organizerRepository; | ||
private readonly IOrganizationRepository _organizationRepository; | ||
|
||
public OrganizerRightsRevokedHandler(IOrganizerRepository organizerRepository, IOrganizationRepository organizationRepository) | ||
{ | ||
_organizerRepository = organizerRepository; | ||
_organizationRepository = organizationRepository; | ||
} | ||
|
||
public async Task HandleAsync(OrganizerRightsRevoked @event, CancellationToken cancellationToken) | ||
{ | ||
var organizer = await _organizerRepository.GetAsync(@event.UserId); | ||
if (organizer is null) | ||
{ | ||
throw new OrganizerNotFoundException(@event.UserId); | ||
} | ||
|
||
var organizerOrganizations = await _organizationRepository.GetOrganizerOrganizationsAsync(@event.UserId); | ||
foreach (var organization in organizerOrganizations) | ||
{ | ||
organization.RemoveOrganizer(organizer); | ||
await _organizationRepository.UpdateAsync(organization); | ||
} | ||
|
||
await _organizerRepository.DeleteAsync(@event.UserId); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...rc/MiniSpace.Services.Organizations.Application/Events/External/OrganizerRightsGranted.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,17 @@ | ||
using Convey.CQRS.Events; | ||
using Convey.MessageBrokers; | ||
using MiniSpace.Services.Organizations.Core.Entities; | ||
|
||
namespace MiniSpace.Services.Organizations.Application.Events.External | ||
{ | ||
[Message("identity") ] | ||
public class OrganizerRightsGranted : IEvent | ||
{ | ||
public Guid UserId { get; } | ||
|
||
public OrganizerRightsGranted(Guid userId) | ||
{ | ||
UserId = userId; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...rc/MiniSpace.Services.Organizations.Application/Events/External/OrganizerRightsRevoked.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,16 @@ | ||
using Convey.CQRS.Events; | ||
using Convey.MessageBrokers; | ||
|
||
namespace MiniSpace.Services.Organizations.Application.Events.External | ||
{ | ||
[Message("identity")] | ||
public class OrganizerRightsRevoked: IEvent | ||
{ | ||
public Guid UserId { get; } | ||
|
||
public OrganizerRightsRevoked(Guid userId) | ||
{ | ||
UserId = userId; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...MiniSpace.Services.Organizations.Application/Exceptions/OrganizerAlreadyAddedException.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,13 @@ | ||
namespace MiniSpace.Services.Organizations.Application.Exceptions | ||
{ | ||
public class OrganizerAlreadyAddedException : AppException | ||
{ | ||
public override string Code { get; } = "organizer_already_added"; | ||
public Guid OrganizerId { get; } | ||
|
||
public OrganizerAlreadyAddedException(Guid organizerId) : base($"Organizer with ID: '{organizerId}' was already added.") | ||
{ | ||
OrganizerId = organizerId; | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...src/MiniSpace.Services.Organizations.Application/Exceptions/OrganizerNotFoundException.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,13 @@ | ||
namespace MiniSpace.Services.Organizations.Application.Exceptions | ||
{ | ||
public class OrganizerNotFoundException : AppException | ||
{ | ||
public override string Code { get; } = "organizer_not_found"; | ||
public Guid OrganizerId { get; } | ||
|
||
public OrganizerNotFoundException(Guid organizerId) : base($"Organizer with ID: {organizerId} was not found.") | ||
{ | ||
OrganizerId = organizerId; | ||
} | ||
} | ||
} |
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
4 changes: 3 additions & 1 deletion
4
...c/MiniSpace.Services.Organizations.Infrastructure/Mongo/Documents/OrganizationDocument.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,11 +1,13 @@ | ||
using Convey.Types; | ||
using MiniSpace.Services.Organizations.Core.Entities; | ||
|
||
namespace MiniSpace.Services.Organizations.Infrastructure.Mongo.Documents | ||
{ | ||
public class OrganizationDocument:IIdentifiable<Guid> | ||
public class OrganizationDocument: IIdentifiable<Guid> | ||
{ | ||
public Guid Id { get; set; } | ||
public string Name { get; set; } | ||
public Guid ParentId { get; set; } | ||
public IEnumerable<Organizer> Organizers { 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