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: Rename AcceptanceContent property of Relationship class #613

Merged
merged 11 commits into from
Apr 23, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace Backbone.Modules.Relationships.Application.Relationships.Commands.Acce
public class AcceptRelationshipCommand : IRequest<AcceptRelationshipResponse>
{
public required string RelationshipId { get; set; }
public byte[]? AcceptanceContent { get; set; }
public byte[]? CreationResponseContent { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<AcceptRelationshipResponse> Handle(AcceptRelationshipCommand r
var relationshipId = RelationshipId.Parse(request.RelationshipId);
var relationship = await _relationshipsRepository.FindRelationship(relationshipId, _activeIdentity, cancellationToken, track: true);

relationship.Accept(_activeIdentity, _activeDevice, request.AcceptanceContent);
relationship.Accept(_activeIdentity, _activeDevice, request.CreationResponseContent);

await _relationshipsRepository.Update(relationship);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<RejectRelationshipResponse> Handle(RejectRelationshipCommand r
var relationship = await _relationshipsRepository.FindRelationship(relationshipId, _activeIdentity, cancellationToken, track: true) ??
throw new NotFoundException(nameof(Relationship));

relationship.Reject(_activeIdentity, _activeDevice);
relationship.Reject(_activeIdentity, _activeDevice, request.CreationResponseContent);

await _relationshipsRepository.Update(relationship);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace Backbone.Modules.Relationships.Application.Relationships.Commands.Reje
public class RejectRelationshipCommand : IRequest<RejectRelationshipResponse>
{
public required string RelationshipId { get; set; }
public byte[]? CreationResponseContent { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<RevokeRelationshipResponse> Handle(RevokeRelationshipCommand r
var relationshipId = RelationshipId.Parse(request.RelationshipId);
var relationship = await _relationshipsRepository.FindRelationship(relationshipId, _activeIdentity, cancellationToken, track: true);

relationship.Revoke(_activeIdentity, _activeDevice);
relationship.Revoke(_activeIdentity, _activeDevice, request.CreationResponseContent);

await _relationshipsRepository.Update(relationship);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ namespace Backbone.Modules.Relationships.Application.Relationships.Commands.Revo
public class RevokeRelationshipCommand : IRequest<RevokeRelationshipResponse>
{
public required string RelationshipId { get; set; }
public byte[]? CreationResponseContent { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class RelationshipDTO : IMapTo<Relationship>
public required IdentityAddress To { get; set; }

public required byte[]? CreationContent { get; set; }
public required byte[]? AcceptanceContent { get; set; }
public required byte[]? CreationResponseContent { get; set; }

public required DateTime CreatedAt { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,27 @@ public async Task<IActionResult> CreateRelationship(CreateRelationshipCommand re
[ProducesError(StatusCodes.Status404NotFound)]
public async Task<IActionResult> AcceptRelationship([FromRoute] string id, [FromBody] AcceptRelationshipRequest request, CancellationToken cancellationToken)
{
var response = await _mediator.Send(new AcceptRelationshipCommand { RelationshipId = id, AcceptanceContent = request.AcceptanceContent }, cancellationToken);
var response = await _mediator.Send(new AcceptRelationshipCommand { RelationshipId = id, CreationResponseContent = request.Content }, cancellationToken);
return Ok(response);
}

[HttpPut("{id}/Reject")]
[ProducesResponseType(typeof(HttpResponseEnvelopeResult<RejectRelationshipResponse>), StatusCodes.Status200OK)]
[ProducesError(StatusCodes.Status400BadRequest)]
[ProducesError(StatusCodes.Status404NotFound)]
public async Task<IActionResult> RejectRelationship([FromRoute] string id, CancellationToken cancellationToken)
public async Task<IActionResult> RejectRelationship([FromRoute] string id, [FromBody] RejectRelationshipRequest request, CancellationToken cancellationToken)
{
var response = await _mediator.Send(new RejectRelationshipCommand { RelationshipId = id }, cancellationToken);
var response = await _mediator.Send(new RejectRelationshipCommand { RelationshipId = id, CreationResponseContent = request.Content }, cancellationToken);
return Ok(response);
}

[HttpPut("{id}/Revoke")]
[ProducesResponseType(typeof(HttpResponseEnvelopeResult<RevokeRelationshipResponse>), StatusCodes.Status200OK)]
[ProducesError(StatusCodes.Status400BadRequest)]
[ProducesError(StatusCodes.Status404NotFound)]
public async Task<IActionResult> RevokeRelationship([FromRoute] string id, CancellationToken cancellationToken)
public async Task<IActionResult> RevokeRelationship([FromRoute] string id, [FromBody] RevokeRelationshipRequest request, CancellationToken cancellationToken)
{
var response = await _mediator.Send(new RevokeRelationshipCommand { RelationshipId = id }, cancellationToken);
var response = await _mediator.Send(new RevokeRelationshipCommand { RelationshipId = id, CreationResponseContent = request.Content }, cancellationToken);
return Ok(response);
}

Expand All @@ -112,5 +112,15 @@ public async Task<IActionResult> TerminateRelationship([FromRoute] string id, Ca

public class AcceptRelationshipRequest
{
public byte[]? AcceptanceContent { get; set; }
public byte[]? Content { get; set; } = Array.Empty<byte>();
}

public class RejectRelationshipRequest
{
public byte[]? Content { get; set; } = Array.Empty<byte>();
}

public class RevokeRelationshipRequest
{
public byte[]? Content { get; set; } = Array.Empty<byte>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Relationship(RelationshipTemplate relationshipTemplate, IdentityAddress a

public RelationshipStatus Status { get; private set; }
public byte[]? CreationContent { get; }
public byte[]? AcceptanceContent { get; private set; }
public byte[]? CreationResponseContent { get; private set; }
public List<RelationshipAuditLogEntry> AuditLog { get; }

public IdentityAddress LastModifiedBy => AuditLog.Last().CreatedBy;
Expand All @@ -71,13 +71,13 @@ private static void EnsureNoOtherRelationshipToPeerExists(IdentityAddress target
throw new DomainException(DomainErrors.RelationshipToTargetAlreadyExists(target));
}

public void Accept(IdentityAddress activeIdentity, DeviceId activeDevice, byte[]? acceptanceContent)
public void Accept(IdentityAddress activeIdentity, DeviceId activeDevice, byte[]? creationResponseContent)
{
EnsureStatus(RelationshipStatus.Pending);
EnsureRelationshipRequestIsAddressedToSelf(activeIdentity);

Status = RelationshipStatus.Active;
AcceptanceContent = acceptanceContent;
CreationResponseContent = creationResponseContent;

var auditLogEntry = new RelationshipAuditLogEntry(
RelationshipAuditLogEntryReason.AcceptanceOfCreation,
Expand All @@ -101,11 +101,12 @@ private void EnsureRelationshipRequestIsCreatedBySelf(IdentityAddress activeIden
throw new DomainException(DomainErrors.CannotRevokeRelationshipRequestNotCreatedByYourself());
}

public void Reject(IdentityAddress activeIdentity, DeviceId activeDevice)
public void Reject(IdentityAddress activeIdentity, DeviceId activeDevice, byte[]? creationResponseContent)
{
EnsureStatus(RelationshipStatus.Pending);
EnsureRelationshipRequestIsAddressedToSelf(activeIdentity);

CreationResponseContent = creationResponseContent;
Status = RelationshipStatus.Rejected;

var auditLogEntry = new RelationshipAuditLogEntry(
Expand All @@ -124,11 +125,12 @@ private void EnsureStatus(RelationshipStatus status)
throw new DomainException(DomainErrors.RelationshipIsNotInCorrectStatus(status));
}

public void Revoke(IdentityAddress activeIdentity, DeviceId activeDevice)
public void Revoke(IdentityAddress activeIdentity, DeviceId activeDevice, byte[]? creationResponseContent)
{
EnsureStatus(RelationshipStatus.Pending);
EnsureRelationshipRequestIsCreatedBySelf(activeIdentity);

CreationResponseContent = creationResponseContent;
Status = RelationshipStatus.Revoked;

var auditLogEntry = new RelationshipAuditLogEntry(
Expand Down
Loading
Loading