Skip to content

Commit

Permalink
updated TenantsController
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidEggenberger committed Jan 7, 2025
1 parent 7b1c41e commit 292c8c4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

namespace Modules.TenantIdentity.Features.DomainFeatures.Tenants.Application.Commands
{
public class UpdateRoleOfMemberInTenant : Command
public class UpdateTenantMembership : Command
{
public Guid TenantId { get; set; }
public Guid UserId { get; set; }
public TenantRole Role { get; set; }
}
public class UpdateRoleOfMemberInTenantCommandHandler : ServerExecutionBase<TenantIdentityModule>, ICommandHandler<UpdateRoleOfMemberInTenant>
public class UpdateTenantMembershipCommandHandler : ServerExecutionBase<TenantIdentityModule>, ICommandHandler<UpdateTenantMembership>
{
public UpdateRoleOfMemberInTenantCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) { }
public async Task HandleAsync(UpdateRoleOfMemberInTenant command, CancellationToken cancellationToken)
public UpdateTenantMembershipCommandHandler(IServiceProvider serviceProvider) : base(serviceProvider) { }
public async Task HandleAsync(UpdateTenantMembership command, CancellationToken cancellationToken)
{
var tenant = await module.TenantIdentityDbContext.GetTenantExtendedByIdAsync(command.TenantId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
namespace Modules.TenantIdentity.Public.DTOs.Tenant.Operations
using Shared.Kernel.DomainKernel;
using System;

namespace Modules.TenantIdentity.Public.DTOs.Tenant.Operations
{
public class ChangeRoleOfTenantMemberDTO
{
public TenantRole Role { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
namespace Modules.TenantIdentity.Public.DTOs.Tenant.Operations
using Shared.Kernel.DomainKernel;
using System;
using System.Reflection.Metadata.Ecma335;

namespace Modules.TenantIdentity.Public.DTOs.Tenant.Operations
{
public class InviteUserToTenantDTO
{
public Guid TenantId { get; set; }
public Guid UserId { get; set; }
public TenantRole Role { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,43 +53,54 @@ public async Task<ActionResult<TenantDTO>> CreateTenant(CreateTenantDTO createTe
return CreatedAtAction(nameof(CreateTenant), createdTenant);
}

[HttpDelete("{id}")]
public async Task<ActionResult> DeleteTenant([FromRoute] Guid id)
[HttpDelete("{tenantId}")]
public async Task<ActionResult> DeleteTenant([FromRoute] Guid tenantId)
{
await commandDispatcher.DispatchAsync<DeleteTenant>(new DeleteTenant { ExecutingUserId = executionContext.UserId, TenantId = id });
var deleteTenant = new DeleteTenant
{
ExecutingUserId = executionContext.UserId,
TenantId = tenantId
};

await commandDispatcher.DispatchAsync<DeleteTenant>(deleteTenant);

return Ok();
}

[HttpPost("{tenantId}/memberships")]
public async Task<ActionResult> AddMember([FromRoute] Guid tenantId, InviteUserToTenantDTO inviteUserToGroupDTO)
public async Task<ActionResult> AddMemberToTenant([FromRoute] Guid tenantId, InviteUserToTenantDTO inviteUserToGroupDTO)
{
var addMember = new AddMemberToTenant
{
ExecutingUserId = executionContext.UserId,

UserId = inviteUserToGroupDTO.UserId,
TenantId = inviteUserToGroupDTO.TenantId,
Role = inviteUserToGroupDTO.Role,
};

await commandDispatcher.DispatchAsync<AddMemberToTenant>(null);

return Ok();
}

[HttpPut("{tenantId}/memberships")]
public async Task<ActionResult> UpdateTenantMembership([FromRoute] Guid tenantId, ChangeRoleOfTenantMemberDTO changeRoleOfTeamMemberDTO)
[HttpPut("{tenantId}/memberships/{userId}")]
public async Task<ActionResult> UpdateTenantMembership([FromRoute] Guid tenantId, [FromRoute] Guid userId, ChangeRoleOfTenantMemberDTO changeRoleOfTeamMemberDTO)
{
var updateRoleOfMemberInTenant = new UpdateRoleOfMemberInTenant
var updateTenantMembership = new UpdateTenantMembership
{

ExecutingUserId = executionContext.UserId,
TenantId = tenantId,
Role = changeRoleOfTeamMemberDTO.Role,
UserId = userId
};

await commandDispatcher.DispatchAsync<UpdateRoleOfMemberInTenant>(updateRoleOfMemberInTenant);
await commandDispatcher.DispatchAsync<UpdateTenantMembership>(updateTenantMembership);

return Ok();
}

[HttpDelete("{tenantId}/memberships/{userId}")]
public async Task<ActionResult> RemoveMember([FromRoute] Guid tenantId, [FromRoute] Guid userId)
public async Task<ActionResult> RemoveMemberFromTenant([FromRoute] Guid tenantId, [FromRoute] Guid userId)
{
var removeMember = new RemoveMemberFromTenant
{
Expand Down

0 comments on commit 292c8c4

Please sign in to comment.