Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consumer API: Get all deletion processes #532

Merged
merged 7 commits into from
Feb 23, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using MediatR;

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

public class GetDeletionProcessesQuery : IRequest<GetDeletionProcessesResponse>
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Backbone.Modules.Devices.Application.DTOs;
using Backbone.Modules.Devices.Domain.Entities.Identities;

namespace Backbone.Modules.Devices.Application.Identities.Queries.GetDeletionProcesses;
public class GetDeletionProcessesResponse
{
public GetDeletionProcessesResponse(IReadOnlyList<IdentityDeletionProcess> processes)
{
DeletionProcesses = processes
.Select(p => new IdentityDeletionProcessDTO(p))
.ToList();
}

public List<IdentityDeletionProcessDTO> DeletionProcesses { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Backbone.BuildingBlocks.Application.Abstractions.Exceptions;
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.UserContext;
using Backbone.Modules.Devices.Application.Infrastructure.Persistence.Repository;
using Backbone.Modules.Devices.Domain.Entities.Identities;
using MediatR;

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

public class Handler : IRequestHandler<GetDeletionProcessesQuery, GetDeletionProcessesResponse>
{
private readonly IIdentitiesRepository _identityRepository;
private readonly IUserContext _userContext;

public Handler(IIdentitiesRepository identityRepository, IUserContext userContext)
{
_identityRepository = identityRepository;
_userContext = userContext;
}

public async Task<GetDeletionProcessesResponse> Handle(GetDeletionProcessesQuery request, CancellationToken cancellationToken)
{
var identity = await _identityRepository.FindByAddress(_userContext.GetAddress(), cancellationToken) ?? throw new NotFoundException(nameof(Identity));
var processes = identity.DeletionProcesses;
var response = new GetDeletionProcessesResponse(processes);

return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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.Application.Identities.Queries.GetDeletionProcesses;
using Backbone.Modules.Devices.Infrastructure.OpenIddict;
using MediatR;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -86,6 +87,14 @@ public async Task<IActionResult> GetDeletionProcess([FromRoute] string id, Cance
var response = await _mediator.Send(new GetDeletionProcessQuery { Id = id }, cancellationToken);
return Ok(response);
}

[HttpGet("Self/DeletionProcesses")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> GetDeletionProcesses(CancellationToken cancellationToken)
{
var response = await _mediator.Send(new GetDeletionProcessesQuery(), cancellationToken);
return Ok(response);
}
}

public class CreateIdentityRequest
Expand Down