-
-
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 endpoint for removing an organizer from organization
- Loading branch information
Showing
6 changed files
with
101 additions
and
9 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
48 changes: 48 additions & 0 deletions
48
...ces.Organizations.Application/Commands/Handlers/RemoveOrganizerFromOrganizationHandler.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,48 @@ | ||
using Convey.CQRS.Commands; | ||
using MiniSpace.Services.Organizations.Application.Exceptions; | ||
using MiniSpace.Services.Organizations.Application.Services; | ||
using MiniSpace.Services.Organizations.Core.Repositories; | ||
|
||
namespace MiniSpace.Services.Organizations.Application.Commands.Handlers | ||
{ | ||
public class RemoveOrganizerFromOrganizationHandler : ICommandHandler<RemoveOrganizerFromOrganization> | ||
{ | ||
private readonly IOrganizationRepository _organizationRepository; | ||
private readonly IOrganizerRepository _organizerRepository; | ||
private readonly IAppContext _appContext; | ||
private readonly IMessageBroker _messageBroker; | ||
|
||
public RemoveOrganizerFromOrganizationHandler(IOrganizationRepository organizationRepository, | ||
IOrganizerRepository organizerRepository, IAppContext appContext, IMessageBroker messageBroker) | ||
{ | ||
_organizationRepository = organizationRepository; | ||
_organizerRepository = organizerRepository; | ||
_appContext = appContext; | ||
_messageBroker = messageBroker; | ||
} | ||
|
||
public async Task HandleAsync(RemoveOrganizerFromOrganization command, CancellationToken cancellationToken) | ||
{ | ||
var identity = _appContext.Identity; | ||
if(identity.IsAuthenticated && !identity.IsAdmin) | ||
{ | ||
throw new Exceptions.UnauthorizedAccessException("admin"); | ||
} | ||
|
||
var organization = await _organizationRepository.GetAsync(command.OrganizationId); | ||
if(organization is null) | ||
{ | ||
throw new OrganizationNotFoundException(command.OrganizationId); | ||
} | ||
|
||
var organizer = await _organizerRepository.GetAsync(command.OrganizerId); | ||
if(organizer is null) | ||
{ | ||
throw new OrganizerNotFoundException(command.OrganizerId); | ||
} | ||
|
||
organization.RemoveOrganizer(organizer); | ||
await _organizationRepository.UpdateAsync(organization); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
.../MiniSpace.Services.Organizations.Application/Commands/RemoveOrganizerFromOrganization.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.Commands; | ||
|
||
namespace MiniSpace.Services.Organizations.Application.Commands | ||
{ | ||
public class RemoveOrganizerFromOrganization : ICommand | ||
{ | ||
public Guid OrganizationId { get; } | ||
public Guid OrganizerId { get; } | ||
|
||
public RemoveOrganizerFromOrganization(Guid organizationId, Guid organizerId) | ||
{ | ||
OrganizationId = organizationId; | ||
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
16 changes: 16 additions & 0 deletions
16
...ions/src/MiniSpace.Services.Organizations.Core/Exceptions/OrganizerIsNotInOrganization.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 @@ | ||
namespace MiniSpace.Services.Organizations.Core.Exceptions | ||
{ | ||
public class OrganizerIsNotInOrganization : DomainException | ||
{ | ||
public override string Code { get; } = "organizer_is_not_in_organization"; | ||
public Guid OrganizerId { get; } | ||
public Guid OrganizationId { get; } | ||
|
||
public OrganizerIsNotInOrganization(Guid organizerId, Guid organizationId) | ||
: base($"Organizer with ID: '{organizerId}' is not in organization with ID: '{organizationId}'.") | ||
{ | ||
OrganizerId = organizerId; | ||
OrganizationId = organizationId; | ||
} | ||
} | ||
} |