Skip to content

Commit

Permalink
Add GetDeletionProcesses Query
Browse files Browse the repository at this point in the history
  • Loading branch information
MH321Productions committed Feb 21, 2024
1 parent 198600c commit 3fbf6ad
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
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(Identity identity)
{
DeletionProcesses = identity.DeletionProcesses
.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,27 @@
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 response = new GetDeletionProcessesResponse(identity);

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

0 comments on commit 3fbf6ad

Please sign in to comment.