Skip to content

Commit

Permalink
Consumer API: Revamp Relationships API (#576)
Browse files Browse the repository at this point in the history
* chore: move entities to Aggregates folder

* feat: creation of Relationship and remove Changes related stuff

* test: split into two tests

* feat: acceptance of creation

* feat: reject creation

* feat: revoke creation

* test: split relationship tests into multiple files

* feat: allow multiple relationships as long as there is only one active

* chore: remove redundant parameter

* refactor: make RelationshipTemplatesRepository.Find return null instead of throwing

* feat: add Handler

* feat: add and use expressions

* chore: don't use AutoMapper and add more tests

* feat: reject relationship

* feat: AcceptRelationshipCommand

* feat: RevokeRelationshipCommand

* feat: add AuditLog to DTOs

* feat: add CreationContent property to RelationshipDTO

* feat: add additional properties to RelationshipCreatedIntegrationEvent and RelationshipStatusChangedIntegrationEvent

* feat: handle new integration events in Synchronization module

* chore: formatting

* test: fix tests

* feat: replace integration events in quotas module with new ones

* feat: add migration

* feat: add controller methods

* chore: fix/ignore compiler warnings

* refactor: cleanup error codes

* feat: add insomnia workspace

* feat: add openapi.yml

* fix: add RelationshipMetadataDTO type and add creationContent property to RelationshipDTO

* refactor: rename Content to CreationContent in request to create a relationship

* chore: update InsomniaWorkspace and openapi.yml

* chore: rename RelationshipStatus "Accepted" to "Active"

* chore: fix merge conflicts

* chore: remove redundant whitespace

* feat: add AcceptanceContent

* fix: avoid error on creation of RelationshipsOverview view when RelationshipChanges table does not exist

* feat: (WIP!!): update Admin API RelationshipOverviews view

* feat: add AcceptanceContent to DTO

* fix: pass AcceptanceContent to AcceptRelationshipCommand

* chore: use postgres in Admin CLI launchSettings.json

* fix: relationships overview migration

* feat: update revamped relationships overview view with audit log

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Daniel Almeida <[email protected]>
  • Loading branch information
3 people authored Apr 16, 2024
1 parent 1d2ae84 commit 8c4f151
Show file tree
Hide file tree
Showing 160 changed files with 4,370 additions and 2,823 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,36 @@ public partial class RelationshipsOverview : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
CREATE VIEW "RelationshipOverviews" AS
SELECT
"Relationships"."From" AS "From",
"Relationships"."To" AS "To",
"Relationships"."RelationshipTemplateId" AS "RelationshipTemplateId",
"Relationships"."Status" AS "Status",
"Relationships"."CreatedAt" AS "CreatedAt",
"RelationshipChanges"."Res_CreatedAt" AS "AnsweredAt",
"RelationshipChanges"."Req_CreatedByDevice" AS "CreatedByDevice",
"RelationshipChanges"."Res_CreatedByDevice" AS "AnsweredByDevice"
FROM
"Relationships"."Relationships" AS "Relationships"
LEFT JOIN
"Relationships"."RelationshipChanges" AS "RelationshipChanges"
ON
"Relationships"."Id" = "RelationshipChanges"."RelationshipId"
WHERE
"RelationshipChanges"."Type" = 10
DO
$$
BEGIN
IF EXISTS (
SELECT FROM information_schema.tables
WHERE table_schema = 'Relationships'
AND table_name = 'RelationshipChanges'
) THEN
CREATE VIEW "RelationshipOverviews" AS
SELECT
"Relationships"."From" AS "From",
"Relationships"."To" AS "To",
"Relationships"."RelationshipTemplateId" AS "RelationshipTemplateId",
"Relationships"."Status" AS "Status",
"Relationships"."CreatedAt" AS "CreatedAt",
"RelationshipChanges"."Res_CreatedAt" AS "AnsweredAt",
"RelationshipChanges"."Req_CreatedByDevice" AS "CreatedByDevice",
"RelationshipChanges"."Res_CreatedByDevice" AS "AnsweredByDevice"
FROM
"Relationships"."Relationships" AS "Relationships"
LEFT JOIN
"Relationships"."RelationshipChanges" AS "RelationshipChanges"
ON
"Relationships"."Id" = "RelationshipChanges"."RelationshipId"
WHERE
"RelationshipChanges"."Type" = 10;
END IF;
END;
$$
""");
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Backbone.AdminApi.Infrastructure.Database.Postgres.Migrations
{
/// <inheritdoc />
public partial class RelationshipsRevamp : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
CREATE OR REPLACE VIEW "RelationshipOverviews" AS
SELECT
"Relationships"."From" AS "From",
"Relationships"."To" AS "To",
"Relationships"."RelationshipTemplateId" AS "RelationshipTemplateId",
"Relationships"."Status" AS "Status",
"AuditLog1"."CreatedAt" AS "CreatedAt",
"AuditLog1"."CreatedByDevice" AS "CreatedByDevice",
"AuditLog2"."CreatedAt" AS "AnsweredAt",
"AuditLog2"."CreatedByDevice" AS "AnsweredByDevice"
FROM "Relationships"."Relationships" AS "Relationships"
LEFT JOIN "Relationships"."RelationshipAuditLog" AS "AuditLog1"
ON "Relationships"."Id" = "AuditLog1"."RelationshipId" AND "AuditLog1"."Reason" = 0
LEFT JOIN "Relationships"."RelationshipAuditLog" AS "AuditLog2"
ON "Relationships"."Id" = "AuditLog2"."RelationshipId" AND "AuditLog2"."Reason" = 1
""");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
CREATE OR REPLACE VIEW "RelationshipOverviews" AS
SELECT
"Relationships"."From" AS "From",
"Relationships"."To" AS "To",
"Relationships"."RelationshipTemplateId" AS "RelationshipTemplateId",
"Relationships"."Status" AS "Status",
"Relationships"."CreatedAt" AS "CreatedAt",
"RelationshipChanges"."Res_CreatedAt" AS "AnsweredAt",
"RelationshipChanges"."Req_CreatedByDevice" AS "CreatedByDevice",
"RelationshipChanges"."Res_CreatedByDevice" AS "AnsweredByDevice"
FROM
"Relationships"."Relationships" AS "Relationships"
LEFT JOIN
"Relationships"."RelationshipChanges" AS "RelationshipChanges"
ON
"Relationships"."Id" = "RelationshipChanges"."RelationshipId"
WHERE
"RelationshipChanges"."Type" = 10
""");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ public partial class RelationshipsOverview : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("""
CREATE VIEW RelationshipOverviews AS
SELECT
[RELATIONSHIPS].[From] AS [From],
[RELATIONSHIPS].[To] AS [To],
[RELATIONSHIPS].[RelationshipTemplateId] AS [RelationshipTemplateId],
[RELATIONSHIPS].[Status] AS [Status],
[RELATIONSHIPS].[CreatedAt] AS [CreatedAt],
[RELATIONSHIPCHANGES].[Res_CreatedAt] AS [AnsweredAt],
[RELATIONSHIPCHANGES].[Req_CreatedByDevice] AS [CreatedByDevice],
[RELATIONSHIPCHANGES].[Res_CreatedByDevice] AS [AnsweredByDevice]
FROM
[Relationships].[Relationships] AS RELATIONSHIPS
LEFT JOIN
[Relationships].[RelationshipChanges] AS RELATIONSHIPCHANGES
ON
[RELATIONSHIPS].[Id] = [RELATIONSHIPCHANGES].[RelationshipId]
WHERE
[RELATIONSHIPCHANGES].[Type] = 10
IF EXISTS (SELECT * FROM information_schema.tables WHERE table_schema = 'Relationships' AND table_name = 'RelationshipChanges')
BEGIN
EXECUTE('CREATE OR ALTER VIEW RelationshipOverviews AS
SELECT
[RELATIONSHIPS].[From] AS [From],
[RELATIONSHIPS].[To] AS [To],
[RELATIONSHIPS].[RelationshipTemplateId] AS [RelationshipTemplateId],
[RELATIONSHIPS].[Status] AS [Status],
[RELATIONSHIPS].[CreatedAt] AS [CreatedAt],
[RELATIONSHIPCHANGES].[Res_CreatedAt] AS [AnsweredAt],
[RELATIONSHIPCHANGES].[Req_CreatedByDevice] AS [CreatedByDevice],
[RELATIONSHIPCHANGES].[Res_CreatedByDevice] AS [AnsweredByDevice]
FROM
[Relationships].[Relationships] AS RELATIONSHIPS
LEFT JOIN
[Relationships].[RelationshipChanges] AS RELATIONSHIPCHANGES
ON
[RELATIONSHIPS].[Id] = [RELATIONSHIPCHANGES].[RelationshipId]
WHERE
[RELATIONSHIPCHANGES].[Type] = 10')
END
""");
}

Expand Down
Loading

0 comments on commit 8c4f151

Please sign in to comment.