Skip to content

Commit

Permalink
feat: return relationship dto when terminating a relationship (#651)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
NikolaVetnic and mergify[bot] authored May 13, 2024
1 parent b1596d9 commit 13cae23
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using Backbone.BuildingBlocks.Application.Abstractions.Infrastructure.UserContext;
using Backbone.DevelopmentKit.Identity.ValueObjects;
using Backbone.Modules.Relationships.Application.Infrastructure.Persistence.Repository;
using Backbone.Modules.Relationships.Application.Relationships.DTOs;
using Backbone.Modules.Relationships.Domain.Aggregates.Relationships;
using Backbone.Modules.Relationships.Domain.DomainEvents.Outgoing;
using MediatR;

namespace Backbone.Modules.Relationships.Application.Relationships.Commands.TerminateRelationship;

public class Handler : IRequestHandler<TerminateRelationshipCommand, TerminateRelationshipResponse>
public class Handler : IRequestHandler<TerminateRelationshipCommand, RelationshipDTO>
{
private readonly IRelationshipsRepository _relationshipsRepository;
private readonly IEventBus _eventBus;
Expand All @@ -23,7 +24,7 @@ public Handler(IRelationshipsRepository relationshipsRepository, IUserContext us
_activeDevice = userContext.GetDeviceId();
}

public async Task<TerminateRelationshipResponse> Handle(TerminateRelationshipCommand request, CancellationToken cancellationToken)
public async Task<RelationshipDTO> Handle(TerminateRelationshipCommand request, CancellationToken cancellationToken)
{
var relationshipId = RelationshipId.Parse(request.RelationshipId);
var relationship = await _relationshipsRepository.FindRelationship(relationshipId, _activeIdentity, cancellationToken, track: true);
Expand All @@ -34,6 +35,6 @@ public async Task<TerminateRelationshipResponse> Handle(TerminateRelationshipCom

_eventBus.Publish(new RelationshipStatusChangedDomainEvent(relationship));

return new TerminateRelationshipResponse(relationship);
return new RelationshipDTO(relationship);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Backbone.Modules.Relationships.Application.Relationships.Commands.CreateRelationship;
using Backbone.Modules.Relationships.Application.Relationships.DTOs;
using MediatR;

namespace Backbone.Modules.Relationships.Application.Relationships.Commands.TerminateRelationship;
public class TerminateRelationshipCommand : IRequest<TerminateRelationshipResponse>
public class TerminateRelationshipCommand : IRequest<RelationshipDTO>
{
public required string RelationshipId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public async Task<IActionResult> RevokeRelationship([FromRoute] string id, [From
}

[HttpPut("{id}/Terminate")]
[ProducesResponseType(typeof(HttpResponseEnvelopeResult<TerminateRelationshipResponse>), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(HttpResponseEnvelopeResult<RelationshipDTO>), StatusCodes.Status200OK)]
[ProducesError(StatusCodes.Status400BadRequest)]
[ProducesError(StatusCodes.Status404NotFound)]
public async Task<IActionResult> TerminateRelationship([FromRoute] string id, CancellationToken cancellationToken)
{
await _mediator.Send(new TerminateRelationshipCommand() { RelationshipId = id }, cancellationToken);
return NoContent();
var relationship = await _mediator.Send(new TerminateRelationshipCommand() { RelationshipId = id }, cancellationToken);
return Ok(relationship);
}

[HttpPut("{id}/Reactivate")]
Expand Down

0 comments on commit 13cae23

Please sign in to comment.