diff --git a/Modules/Devices/src/Devices.Application/Identities/Queries/GetDeletionProcess/GetDeletionProcessQuery.cs b/Modules/Devices/src/Devices.Application/Identities/Queries/GetDeletionProcess/GetDeletionProcessQuery.cs new file mode 100644 index 0000000000..3f54f3e752 --- /dev/null +++ b/Modules/Devices/src/Devices.Application/Identities/Queries/GetDeletionProcess/GetDeletionProcessQuery.cs @@ -0,0 +1,9 @@ +using Backbone.Modules.Devices.Application.DTOs; +using MediatR; + +namespace Backbone.Modules.Devices.Application.Identities.Queries.GetDeletionProcess; + +public class GetDeletionProcessQuery : IRequest +{ + public required string Id { get; set; } +} diff --git a/Modules/Devices/src/Devices.Application/Identities/Queries/GetDeletionProcess/Handler.cs b/Modules/Devices/src/Devices.Application/Identities/Queries/GetDeletionProcess/Handler.cs new file mode 100644 index 0000000000..91e547dce5 --- /dev/null +++ b/Modules/Devices/src/Devices.Application/Identities/Queries/GetDeletionProcess/Handler.cs @@ -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 +{ + private readonly IIdentitiesRepository _identitiesRepository; + private readonly IUserContext _userContext; + + public Handler(IIdentitiesRepository identitiesRepository, IUserContext userContext) + { + _identitiesRepository = identitiesRepository; + _userContext = userContext; + } + + public async Task 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; + } +} diff --git a/Modules/Devices/src/Devices.ConsumerApi/Controllers/IdentitiesController.cs b/Modules/Devices/src/Devices.ConsumerApi/Controllers/IdentitiesController.cs index ac33756002..fc0647a196 100644 --- a/Modules/Devices/src/Devices.ConsumerApi/Controllers/IdentitiesController.cs +++ b/Modules/Devices/src/Devices.ConsumerApi/Controllers/IdentitiesController.cs @@ -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; @@ -76,6 +77,15 @@ public async Task 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 GetDeletionProcess([FromRoute] string id, CancellationToken cancellationToken) + { + var response = await _mediator.Send(new GetDeletionProcessQuery { Id = id }, cancellationToken); + return Ok(response); + } } public class CreateIdentityRequest