From 096a7ff85ae592ee4b080c7848aa2396920b4c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Vetni=C4=87?= <62119280+NikolaVetnic@users.noreply.github.com> Date: Tue, 23 Apr 2024 14:35:52 +0200 Subject: [PATCH] Consumer API: Rename AcceptanceContent property of Relationship class (#613) * feat: rename field to CreationResponseContent * feat: update AcceptRelationshipRequest property * feat: update Content property when revoking and rejecting * fix: update method calls with additional parameter * fix: update method calls * chore: remove unnecessarily added property * fix: update ctor to fix the compiler error --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .../AcceptRelationshipCommand.cs | 2 +- .../Commands/AcceptRelationship/Handler.cs | 2 +- .../Commands/RejectRelationship/Handler.cs | 2 +- .../RejectRelationshipCommand.cs | 1 + .../Commands/RevokeRelationship/Handler.cs | 2 +- .../RevokeRelationshipCommand.cs | 1 + .../Relationships/DTOs/RelationshipDTO.cs | 2 +- .../Controllers/RelationshipsController.cs | 22 +- .../Aggregates/Relationships/Relationship.cs | 12 +- ...ntentToCreationResponseContent.Designer.cs | 250 ++++++++++++++++++ ...eptanceContentToCreationResponseContent.cs | 30 +++ .../RelationshipsDbContextModelSnapshot.cs | 6 +- ...ntentToCreationResponseContent.Designer.cs | 250 ++++++++++++++++++ ...eptanceContentToCreationResponseContent.cs | 30 +++ .../RelationshipsDbContextModelSnapshot.cs | 6 +- .../RelationshipEntityTypeConfiguration.cs | 2 +- .../TestHelpers/TestData.cs | 4 +- .../Relationships/AcceptRelationshipTests.cs | 2 +- .../Relationships/RejectRelationshipTests.cs | 10 +- .../Relationships/RevokeRelationshipTests.cs | 10 +- 20 files changed, 610 insertions(+), 36 deletions(-) create mode 100644 Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/20240422120710_RenameAcceptanceContentToCreationResponseContent.Designer.cs create mode 100644 Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/20240422120710_RenameAcceptanceContentToCreationResponseContent.cs create mode 100644 Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/20240422120659_RenameAcceptanceContentToCreationResponseContent.Designer.cs create mode 100644 Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/20240422120659_RenameAcceptanceContentToCreationResponseContent.cs diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationship/AcceptRelationshipCommand.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationship/AcceptRelationshipCommand.cs index 6550b840ce..9deda08417 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationship/AcceptRelationshipCommand.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationship/AcceptRelationshipCommand.cs @@ -5,5 +5,5 @@ namespace Backbone.Modules.Relationships.Application.Relationships.Commands.Acce public class AcceptRelationshipCommand : IRequest { public required string RelationshipId { get; set; } - public byte[]? AcceptanceContent { get; set; } + public byte[]? CreationResponseContent { get; set; } } diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationship/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationship/Handler.cs index 9cde372a17..66dff25cc4 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationship/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/AcceptRelationship/Handler.cs @@ -28,7 +28,7 @@ public async Task 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); diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationship/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationship/Handler.cs index 7eaa29b5af..48e0fd8a2c 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationship/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationship/Handler.cs @@ -31,7 +31,7 @@ public async Task 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); diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationship/RejectRelationshipCommand.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationship/RejectRelationshipCommand.cs index cd0577d8a2..849c451deb 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationship/RejectRelationshipCommand.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RejectRelationship/RejectRelationshipCommand.cs @@ -5,4 +5,5 @@ namespace Backbone.Modules.Relationships.Application.Relationships.Commands.Reje public class RejectRelationshipCommand : IRequest { public required string RelationshipId { get; set; } + public byte[]? CreationResponseContent { get; set; } } diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationship/Handler.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationship/Handler.cs index 3e688053d7..15d6aa18bb 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationship/Handler.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationship/Handler.cs @@ -28,7 +28,7 @@ public async Task 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); diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationship/RevokeRelationshipCommand.cs b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationship/RevokeRelationshipCommand.cs index 32241f9acc..a6341b4e3f 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationship/RevokeRelationshipCommand.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/Commands/RevokeRelationship/RevokeRelationshipCommand.cs @@ -5,4 +5,5 @@ namespace Backbone.Modules.Relationships.Application.Relationships.Commands.Revo public class RevokeRelationshipCommand : IRequest { public required string RelationshipId { get; set; } + public byte[]? CreationResponseContent { get; set; } } diff --git a/Modules/Relationships/src/Relationships.Application/Relationships/DTOs/RelationshipDTO.cs b/Modules/Relationships/src/Relationships.Application/Relationships/DTOs/RelationshipDTO.cs index f606deed07..8350edd468 100644 --- a/Modules/Relationships/src/Relationships.Application/Relationships/DTOs/RelationshipDTO.cs +++ b/Modules/Relationships/src/Relationships.Application/Relationships/DTOs/RelationshipDTO.cs @@ -14,7 +14,7 @@ public class RelationshipDTO : IMapTo 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; } diff --git a/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs b/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs index 2f935c7e65..4ac5d49d26 100644 --- a/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs +++ b/Modules/Relationships/src/Relationships.ConsumerApi/Controllers/RelationshipsController.cs @@ -75,7 +75,7 @@ public async Task CreateRelationship(CreateRelationshipCommand re [ProducesError(StatusCodes.Status404NotFound)] public async Task 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); } @@ -83,9 +83,9 @@ public async Task AcceptRelationship([FromRoute] string id, [From [ProducesResponseType(typeof(HttpResponseEnvelopeResult), StatusCodes.Status200OK)] [ProducesError(StatusCodes.Status400BadRequest)] [ProducesError(StatusCodes.Status404NotFound)] - public async Task RejectRelationship([FromRoute] string id, CancellationToken cancellationToken) + public async Task 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); } @@ -93,9 +93,9 @@ public async Task RejectRelationship([FromRoute] string id, Cance [ProducesResponseType(typeof(HttpResponseEnvelopeResult), StatusCodes.Status200OK)] [ProducesError(StatusCodes.Status400BadRequest)] [ProducesError(StatusCodes.Status404NotFound)] - public async Task RevokeRelationship([FromRoute] string id, CancellationToken cancellationToken) + public async Task 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); } @@ -112,5 +112,15 @@ public async Task TerminateRelationship([FromRoute] string id, Ca public class AcceptRelationshipRequest { - public byte[]? AcceptanceContent { get; set; } + public byte[]? Content { get; set; } = Array.Empty(); +} + +public class RejectRelationshipRequest +{ + public byte[]? Content { get; set; } = Array.Empty(); +} + +public class RevokeRelationshipRequest +{ + public byte[]? Content { get; set; } = Array.Empty(); } diff --git a/Modules/Relationships/src/Relationships.Domain/Aggregates/Relationships/Relationship.cs b/Modules/Relationships/src/Relationships.Domain/Aggregates/Relationships/Relationship.cs index 03a5ba123b..f4c68fe879 100644 --- a/Modules/Relationships/src/Relationships.Domain/Aggregates/Relationships/Relationship.cs +++ b/Modules/Relationships/src/Relationships.Domain/Aggregates/Relationships/Relationship.cs @@ -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 AuditLog { get; } public IdentityAddress LastModifiedBy => AuditLog.Last().CreatedBy; @@ -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, @@ -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( @@ -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( diff --git a/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/20240422120710_RenameAcceptanceContentToCreationResponseContent.Designer.cs b/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/20240422120710_RenameAcceptanceContentToCreationResponseContent.Designer.cs new file mode 100644 index 0000000000..e18a624789 --- /dev/null +++ b/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/20240422120710_RenameAcceptanceContentToCreationResponseContent.Designer.cs @@ -0,0 +1,250 @@ +// +using System; +using Backbone.Modules.Relationships.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Backbone.Modules.Relationships.Infrastructure.Database.Postgres.Migrations +{ + [DbContext(typeof(RelationshipsDbContext))] + [Migration("20240422120710_RenameAcceptanceContentToCreationResponseContent")] + partial class RenameAcceptanceContentToCreationResponseContent + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Relationships") + .HasAnnotation("ProductVersion", "8.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplate", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("Content") + .HasColumnType("bytea"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("CreatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ExpiresAt") + .HasColumnType("timestamp with time zone"); + + b.Property("MaxNumberOfAllocations") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("RelationshipTemplates", "Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplateAllocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AllocatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("AllocatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("AllocatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("RelationshipTemplateId") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.HasIndex("RelationshipTemplateId", "AllocatedBy"); + + b.ToTable("RelationshipTemplateAllocations", "Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.Relationship", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreationContent") + .HasColumnType("bytea"); + + b.Property("CreationResponseContent") + .HasColumnType("bytea"); + + b.Property("From") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("RelationshipTemplateId") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("To") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.HasIndex("From"); + + b.HasIndex("RelationshipTemplateId"); + + b.HasIndex("To"); + + b.ToTable("Relationships", "Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.RelationshipAuditLogEntry", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("character(36)") + .IsFixedLength(); + + b.Property("CreatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.Property("NewStatus") + .HasColumnType("integer"); + + b.Property("OldStatus") + .HasColumnType("integer"); + + b.Property("Reason") + .HasColumnType("integer"); + + b.Property("RelationshipId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("character(20)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.HasIndex("RelationshipId"); + + b.ToTable("RelationshipAuditLog", "Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplateAllocation", b => + { + b.HasOne("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplate", null) + .WithMany("Allocations") + .HasForeignKey("RelationshipTemplateId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.Relationship", b => + { + b.HasOne("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplate", "RelationshipTemplate") + .WithMany("Relationships") + .HasForeignKey("RelationshipTemplateId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("RelationshipTemplate"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.RelationshipAuditLogEntry", b => + { + b.HasOne("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.Relationship", null) + .WithMany("AuditLog") + .HasForeignKey("RelationshipId"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplate", b => + { + b.Navigation("Allocations"); + + b.Navigation("Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.Relationship", b => + { + b.Navigation("AuditLog"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/20240422120710_RenameAcceptanceContentToCreationResponseContent.cs b/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/20240422120710_RenameAcceptanceContentToCreationResponseContent.cs new file mode 100644 index 0000000000..2970211583 --- /dev/null +++ b/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/20240422120710_RenameAcceptanceContentToCreationResponseContent.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Backbone.Modules.Relationships.Infrastructure.Database.Postgres.Migrations +{ + /// + public partial class RenameAcceptanceContentToCreationResponseContent : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "AcceptanceContent", + schema: "Relationships", + table: "Relationships", + newName: "CreationResponseContent"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "CreationResponseContent", + schema: "Relationships", + table: "Relationships", + newName: "AcceptanceContent"); + } + } +} diff --git a/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/RelationshipsDbContextModelSnapshot.cs b/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/RelationshipsDbContextModelSnapshot.cs index d7f99b5a41..54d1162bc1 100644 --- a/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/RelationshipsDbContextModelSnapshot.cs +++ b/Modules/Relationships/src/Relationships.Infrastructure.Database.Postgres/Migrations/RelationshipsDbContextModelSnapshot.cs @@ -112,15 +112,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("character(20)") .IsFixedLength(); - b.Property("AcceptanceContent") - .HasColumnType("bytea"); - b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); b.Property("CreationContent") .HasColumnType("bytea"); + b.Property("CreationResponseContent") + .HasColumnType("bytea"); + b.Property("From") .IsRequired() .HasMaxLength(36) diff --git a/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/20240422120659_RenameAcceptanceContentToCreationResponseContent.Designer.cs b/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/20240422120659_RenameAcceptanceContentToCreationResponseContent.Designer.cs new file mode 100644 index 0000000000..b24384bf70 --- /dev/null +++ b/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/20240422120659_RenameAcceptanceContentToCreationResponseContent.Designer.cs @@ -0,0 +1,250 @@ +// +using System; +using Backbone.Modules.Relationships.Infrastructure.Persistence.Database; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Backbone.Modules.Relationships.Infrastructure.Database.SqlServer.Migrations +{ + [DbContext(typeof(RelationshipsDbContext))] + [Migration("20240422120659_RenameAcceptanceContentToCreationResponseContent")] + partial class RenameAcceptanceContentToCreationResponseContent + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasDefaultSchema("Relationships") + .HasAnnotation("ProductVersion", "8.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplate", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("Content") + .HasColumnType("varbinary(max)"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("CreatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("ExpiresAt") + .HasColumnType("datetime2"); + + b.Property("MaxNumberOfAllocations") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("RelationshipTemplates", "Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplateAllocation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AllocatedAt") + .HasColumnType("datetime2"); + + b.Property("AllocatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("AllocatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("RelationshipTemplateId") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.HasIndex("RelationshipTemplateId", "AllocatedBy"); + + b.ToTable("RelationshipTemplateAllocations", "Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.Relationship", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreationContent") + .HasColumnType("varbinary(max)"); + + b.Property("CreationResponseContent") + .HasColumnType("varbinary(max)"); + + b.Property("From") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("RelationshipTemplateId") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("To") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.HasIndex("From"); + + b.HasIndex("RelationshipTemplateId"); + + b.HasIndex("To"); + + b.ToTable("Relationships", "Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.RelationshipAuditLogEntry", b => + { + b.Property("Id") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("char(36)") + .IsFixedLength(); + + b.Property("CreatedByDevice") + .IsRequired() + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.Property("NewStatus") + .HasColumnType("int"); + + b.Property("OldStatus") + .HasColumnType("int"); + + b.Property("Reason") + .HasColumnType("int"); + + b.Property("RelationshipId") + .HasMaxLength(20) + .IsUnicode(false) + .HasColumnType("char(20)") + .IsFixedLength(); + + b.HasKey("Id"); + + b.HasIndex("RelationshipId"); + + b.ToTable("RelationshipAuditLog", "Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplateAllocation", b => + { + b.HasOne("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplate", null) + .WithMany("Allocations") + .HasForeignKey("RelationshipTemplateId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.Relationship", b => + { + b.HasOne("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplate", "RelationshipTemplate") + .WithMany("Relationships") + .HasForeignKey("RelationshipTemplateId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("RelationshipTemplate"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.RelationshipAuditLogEntry", b => + { + b.HasOne("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.Relationship", null) + .WithMany("AuditLog") + .HasForeignKey("RelationshipId"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.RelationshipTemplates.RelationshipTemplate", b => + { + b.Navigation("Allocations"); + + b.Navigation("Relationships"); + }); + + modelBuilder.Entity("Backbone.Modules.Relationships.Domain.Aggregates.Relationships.Relationship", b => + { + b.Navigation("AuditLog"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/20240422120659_RenameAcceptanceContentToCreationResponseContent.cs b/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/20240422120659_RenameAcceptanceContentToCreationResponseContent.cs new file mode 100644 index 0000000000..72c2b46b32 --- /dev/null +++ b/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/20240422120659_RenameAcceptanceContentToCreationResponseContent.cs @@ -0,0 +1,30 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Backbone.Modules.Relationships.Infrastructure.Database.SqlServer.Migrations +{ + /// + public partial class RenameAcceptanceContentToCreationResponseContent : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "AcceptanceContent", + schema: "Relationships", + table: "Relationships", + newName: "CreationResponseContent"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "CreationResponseContent", + schema: "Relationships", + table: "Relationships", + newName: "AcceptanceContent"); + } + } +} diff --git a/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/RelationshipsDbContextModelSnapshot.cs b/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/RelationshipsDbContextModelSnapshot.cs index 65b28d75ee..e85e469e14 100644 --- a/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/RelationshipsDbContextModelSnapshot.cs +++ b/Modules/Relationships/src/Relationships.Infrastructure.Database.SqlServer/Migrations/RelationshipsDbContextModelSnapshot.cs @@ -112,15 +112,15 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("char(20)") .IsFixedLength(); - b.Property("AcceptanceContent") - .HasColumnType("varbinary(max)"); - b.Property("CreatedAt") .HasColumnType("datetime2"); b.Property("CreationContent") .HasColumnType("varbinary(max)"); + b.Property("CreationResponseContent") + .HasColumnType("varbinary(max)"); + b.Property("From") .IsRequired() .HasMaxLength(36) diff --git a/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/EntityTypeConfigurations/RelationshipEntityTypeConfiguration.cs b/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/EntityTypeConfigurations/RelationshipEntityTypeConfiguration.cs index 7d3812d0aa..886e23748c 100644 --- a/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/EntityTypeConfigurations/RelationshipEntityTypeConfiguration.cs +++ b/Modules/Relationships/src/Relationships.Infrastructure/Persistence/Database/EntityTypeConfigurations/RelationshipEntityTypeConfiguration.cs @@ -17,6 +17,6 @@ public void Configure(EntityTypeBuilder builder) builder.Property(x => x.CreatedAt); builder.Property(x => x.CreationContent); - builder.Property(x => x.AcceptanceContent); + builder.Property(x => x.CreationResponseContent); } } diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/TestHelpers/TestData.cs b/Modules/Relationships/test/Relationships.Domain.Tests/TestHelpers/TestData.cs index e2cfff8d60..3449f27323 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/TestHelpers/TestData.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/TestHelpers/TestData.cs @@ -32,14 +32,14 @@ public static Relationship CreateActiveRelationship(IdentityAddress? from = null public static Relationship CreateRejectedRelationship() { var relationship = new Relationship(RELATIONSHIP_TEMPLATE_OF_2, IDENTITY_1, DEVICE_1, null, []); - relationship.Reject(IDENTITY_2, DEVICE_2); + relationship.Reject(IDENTITY_2, DEVICE_2, null); return relationship; } public static Relationship CreateRevokedRelationship() { var relationship = new Relationship(RELATIONSHIP_TEMPLATE_OF_2, IDENTITY_1, DEVICE_1, null, []); - relationship.Revoke(IDENTITY_1, DEVICE_1); + relationship.Revoke(IDENTITY_1, DEVICE_1, null); return relationship; } diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/AcceptRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/AcceptRelationshipTests.cs index ab8dbca875..b2ed410ad2 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/AcceptRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/AcceptRelationshipTests.cs @@ -22,7 +22,7 @@ public void Accepting_creation_transitions_relationship_to_status_active() // Assert relationship.Status.Should().Be(RelationshipStatus.Active); - relationship.AcceptanceContent.Should().BeEquivalentTo([0]); + relationship.CreationResponseContent.Should().BeEquivalentTo([0]); } [Fact] diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RejectRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RejectRelationshipTests.cs index 51b5a70bc2..a3d2fa0303 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RejectRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RejectRelationshipTests.cs @@ -18,7 +18,7 @@ public void Reject_creation_transitions_relationship_to_status_rejected() var relationship = CreatePendingRelationship(); // Act - relationship.Reject(IDENTITY_2, DEVICE_2); + relationship.Reject(IDENTITY_2, DEVICE_2, null); // Assert relationship.Status.Should().Be(RelationshipStatus.Rejected); @@ -33,7 +33,7 @@ public void Rejecting_creation_creates_an_audit_log_entry() var relationship = CreatePendingRelationship(); // Act - relationship.Reject(IDENTITY_2, DEVICE_2); + relationship.Reject(IDENTITY_2, DEVICE_2, null); // Assert relationship.AuditLog.Should().HaveCount(2); @@ -56,7 +56,7 @@ public void Can_only_reject_creation_when_relationship_is_in_status_pending() var relationship = CreateActiveRelationship(); // Act - var acting = () => relationship.Reject(IDENTITY_2, DEVICE_2); + var acting = () => relationship.Reject(IDENTITY_2, DEVICE_2, null); // Assert acting.Should().Throw().WithError( @@ -72,7 +72,7 @@ public void Cannot_reject_own_relationship_request() var relationship = CreatePendingRelationship(); // Act - var acting = () => relationship.Reject(IDENTITY_1, DEVICE_1); + var acting = () => relationship.Reject(IDENTITY_1, DEVICE_1, null); // Assert acting.Should().Throw().WithError("error.platform.validation.relationshipRequest.cannotAcceptOrRejectRelationshipRequestAddressedToSomeoneElse"); @@ -86,7 +86,7 @@ public void Cannot_reject_foreign_relationship_request() var foreignAddress = IdentityAddress.ParseUnsafe("some-other-identity"); // Act - var acting = () => relationship.Reject(foreignAddress, DeviceId.New()); + var acting = () => relationship.Reject(foreignAddress, DeviceId.New(), null); // Assert acting.Should().Throw().WithError("error.platform.validation.relationshipRequest.cannotAcceptOrRejectRelationshipRequestAddressedToSomeoneElse"); diff --git a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RevokeRelationshipTests.cs b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RevokeRelationshipTests.cs index 511d5024cb..180593c542 100644 --- a/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RevokeRelationshipTests.cs +++ b/Modules/Relationships/test/Relationships.Domain.Tests/Tests/Aggregates/Relationships/RevokeRelationshipTests.cs @@ -18,7 +18,7 @@ public void Revoke_creation_transitions_relationship_to_status_revoked() var relationship = CreatePendingRelationship(); // Act - relationship.Revoke(IDENTITY_1, DEVICE_1); + relationship.Revoke(IDENTITY_1, DEVICE_1, null); // Assert relationship.Status.Should().Be(RelationshipStatus.Revoked); @@ -33,7 +33,7 @@ public void Revoking_creation_creates_an_audit_log_entry() var relationship = CreatePendingRelationship(); // Act - relationship.Revoke(IDENTITY_1, DEVICE_1); + relationship.Revoke(IDENTITY_1, DEVICE_1, null); // Assert relationship.AuditLog.Should().HaveCount(2); @@ -56,7 +56,7 @@ public void Can_only_revoke_creation_when_relationship_is_in_status_pending() var relationship = CreateActiveRelationship(); // Act - var acting = () => relationship.Revoke(IDENTITY_2, DEVICE_2); + var acting = () => relationship.Revoke(IDENTITY_2, DEVICE_2, null); // Assert acting.Should().Throw().WithError( @@ -72,7 +72,7 @@ public void Cannot_revoke_own_relationship_request() var relationship = CreatePendingRelationship(); // Act - var acting = () => relationship.Revoke(IDENTITY_2, DEVICE_2); + var acting = () => relationship.Revoke(IDENTITY_2, DEVICE_2, null); // Assert acting.Should().Throw().WithError("error.platform.validation.relationshipRequest.cannotRevokeRelationshipRequestNotCreatedByYourself"); @@ -86,7 +86,7 @@ public void Cannot_revoke_foreign_relationship_request() var foreignAddress = IdentityAddress.ParseUnsafe("some-other-identity"); // Act - var acting = () => relationship.Revoke(foreignAddress, DeviceId.New()); + var acting = () => relationship.Revoke(foreignAddress, DeviceId.New(), null); // Assert acting.Should().Throw().WithError("error.platform.validation.relationshipRequest.cannotRevokeRelationshipRequestNotCreatedByYourself");