Skip to content

Commit

Permalink
Add GetDeletionProcess Query
Browse files Browse the repository at this point in the history
  • Loading branch information
MH321Productions committed Feb 21, 2024
1 parent 6c099a7 commit 8c187d1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Backbone.Modules.Devices.Application.DTOs;
using MediatR;

namespace Backbone.Modules.Devices.Application.Identities.Queries.GetDeletionProcess;

public class GetDeletionProcessQuery : IRequest<IdentityDeletionProcessDTO>
{
public required string Id { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Backbone.BuildingBlocks.Application.Abstractions.Exceptions;
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.UserContext;
using Backbone.Modules.Devices.Application.DTOs;
using Backbone.Modules.Devices.Application.Infrastructure.Persistence.Repository;
using Backbone.Modules.Devices.Domain.Entities.Identities;
using MediatR;

namespace Backbone.Modules.Devices.Application.Identities.Queries.GetDeletionProcess;

public class Handler : IRequestHandler<GetDeletionProcessQuery, IdentityDeletionProcessDTO>
{
private readonly IIdentitiesRepository _identitiesRepository;
private readonly IUserContext _userContext;

public Handler(IIdentitiesRepository identitiesRepository, IUserContext userContext)
{
_identitiesRepository = identitiesRepository;
_userContext = userContext;
}

public async Task<IdentityDeletionProcessDTO> Handle(GetDeletionProcessQuery request, CancellationToken cancellationToken)
{
var identity = await _identitiesRepository.FindByAddress(_userContext.GetAddress(), cancellationToken) ?? throw new NotFoundException(nameof(Identity));
var deletionProcess = identity.DeletionProcesses.FirstOrDefault(p => p.Id == request.Id) ?? throw new NotFoundException(nameof(IdentityDeletionProcess));
var response = new IdentityDeletionProcessDTO(deletionProcess);

return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Backbone.Modules.Devices.Application.Identities.Commands.ApproveDeletionProcess;
using Backbone.Modules.Devices.Application.Identities.Commands.CreateIdentity;
using Backbone.Modules.Devices.Application.Identities.Commands.StartDeletionProcessAsOwner;
using Backbone.Modules.Devices.Application.Identities.Queries.GetDeletionProcess;
using Backbone.Modules.Devices.Infrastructure.OpenIddict;
using MediatR;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -76,6 +77,15 @@ public async Task<IActionResult> ApproveDeletionProcess([FromRoute] string id, C
var response = await _mediator.Send(new ApproveDeletionProcessCommand(id), cancellationToken);
return Ok(response);
}

[HttpGet("Self/DeletionProcesses/{id}")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesError(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetDeletionProcess([FromRoute] string id, CancellationToken cancellationToken)
{
var response = await _mediator.Send(new GetDeletionProcessQuery { Id = id }, cancellationToken);
return Ok(response);
}
}

public class CreateIdentityRequest
Expand Down

0 comments on commit 8c187d1

Please sign in to comment.