Skip to content

Commit

Permalink
feat: add integration database latest item projections
Browse files Browse the repository at this point in the history
  • Loading branch information
jvandaal committed Jan 15, 2024
1 parent a763ddf commit 5a5b367
Show file tree
Hide file tree
Showing 37 changed files with 4,821 additions and 13 deletions.
7 changes: 7 additions & 0 deletions BuildingRegistry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuildingRegistry.Consumer.R
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuildingRegistry.Snapshot.Verifier", "src\BuildingRegistry.Snapshot.Verifier\BuildingRegistry.Snapshot.Verifier.csproj", "{6F18B5C9-0E57-4352-B320-7976094B0738}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuildingRegistry.Projections.Integration", "src\BuildingRegistry.Projections.Integration\BuildingRegistry.Projections.Integration.csproj", "{2CD597C6-43AB-4AB8-AF3A-5AC186AB92A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -184,6 +186,10 @@ Global
{6F18B5C9-0E57-4352-B320-7976094B0738}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F18B5C9-0E57-4352-B320-7976094B0738}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F18B5C9-0E57-4352-B320-7976094B0738}.Release|Any CPU.Build.0 = Release|Any CPU
{2CD597C6-43AB-4AB8-AF3A-5AC186AB92A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CD597C6-43AB-4AB8-AF3A-5AC186AB92A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CD597C6-43AB-4AB8-AF3A-5AC186AB92A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CD597C6-43AB-4AB8-AF3A-5AC186AB92A3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -214,6 +220,7 @@ Global
{72C98F9C-C576-4DFC-BAD6-4249E2AB64F1} = {1A034126-30E6-416B-BB2E-F5786E07B178}
{7ADEA3CC-89A7-40B2-936A-3DC0BBF755B5} = {24B47154-C5F0-4356-B059-49A1E72C38A6}
{6F18B5C9-0E57-4352-B320-7976094B0738} = {24B47154-C5F0-4356-B059-49A1E72C38A6}
{2CD597C6-43AB-4AB8-AF3A-5AC186AB92A3} = {24B47154-C5F0-4356-B059-49A1E72C38A6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65FA30D5-DDFC-40EC-9BC9-3BF93D1B430F}
Expand Down
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ nuget MediatR.Contracts 2.0.1
nuget MediatR.Extensions.Microsoft.DependencyInjection 10.0.1

nuget Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite 6.0.3
nuget Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite 6.0.3
nuget NetTopologySuite 2.4.0

nuget NodaTime 3.1.6
Expand Down
8 changes: 8 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@ NUGET
Microsoft.NETCore.Platforms (>= 1.1)
NetTopologySuite (2.4)
System.Memory (>= 4.5.3)
NetTopologySuite.IO.PostGis (2.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
NetTopologySuite (>= 2.0 < 3.0.0-A)
NetTopologySuite.IO.SqlServerBytes (2.1) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
NetTopologySuite (>= 2.0 < 3.0.0-A)
Newtonsoft.Json (13.0.1)
Expand Down Expand Up @@ -1073,6 +1075,12 @@ NUGET
NETStandard.Library (>= 1.6.1) - restriction: || (&& (== net472) (< net46)) (== net6.0)
Npgsql (>= 3.2.2)
Npgsql.EntityFrameworkCore.PostgreSQL (>= 2.0.0-preview1)
Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite (6.0.3)
Npgsql.EntityFrameworkCore.PostgreSQL (>= 6.0.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Npgsql.NetTopologySuite (>= 6.0.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Npgsql.NetTopologySuite (6.0.3) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
NetTopologySuite.IO.PostGis (>= 2.1)
Npgsql (>= 6.0.3)
NSwag.CodeGeneration (13.15.10) - restriction: || (&& (== net472) (>= net6.0)) (== net6.0)
Newtonsoft.Json (>= 9.0.1)
NJsonSchema (>= 10.6.10)
Expand Down
2 changes: 2 additions & 0 deletions src/BuildingRegistry.Infrastructure/Schema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class Schema
public const string BackOfficeProjections = "BuildingRegistryBackOfficeProjections";
public const string Producer = "BuildingRegistryProducer";
public const string ProducerSnapshotOslo = "BuildingRegistryProducerSnapshotOslo";
public const string Integration = "integration_building";
}

public static class MigrationTables
Expand All @@ -35,5 +36,6 @@ public static class MigrationTables
public const string MigratorProjection = "__EFMigrationsHistoryMigrationProjection";
public const string Producer = "__EFMigrationsHistoryProducer";
public const string ProducerSnapshotOslo = "__EFMigrationsHistoryProducerSnapshotOslo";
public const string Integration = "__EFMigrationsHistory";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
namespace BuildingRegistry.Projections.Integration.Building.LatestItem
{
using System;
using Be.Vlaanderen.Basisregisters.GrAr.Common;
using Be.Vlaanderen.Basisregisters.Utilities;
using BuildingRegistry.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using NetTopologySuite.Geometries;
using NodaTime;

public sealed class BuildingLatestItem
{
public const string VersionTimestampBackingPropertyName = nameof(VersionTimestampAsDateTimeOffset);
public const string CreatedTimestampBackingPropertyName = nameof(CreatedOnTimestampAsDateTimeOffset);

public int BuildingPersistentLocalId { get; set; }
public string Status { get; set; }
public string OsloStatus { get; set; }
public string GeometryMethod { get; set; }
public Geometry Geometry { get; set; }
public string? NisCode { get; set; }
public bool IsRemoved { get; set; }

public string PuriId { get; set; }
public string Namespace { get; set; }

public string VersionAsString { get; set; }
private DateTimeOffset VersionTimestampAsDateTimeOffset { get; set; }
public Instant VersionTimestamp
{
get => Instant.FromDateTimeOffset(VersionTimestampAsDateTimeOffset);
set
{
VersionTimestampAsDateTimeOffset = value.ToDateTimeOffset();
VersionAsString = new Rfc3339SerializableDateTimeOffset(value.ToBelgianDateTimeOffset()).ToString();
}
}

public string CreatedOnAsString { get; set; }
private DateTimeOffset CreatedOnTimestampAsDateTimeOffset { get; set; }
public Instant CreatedOnTimestamp
{
get => Instant.FromDateTimeOffset(CreatedOnTimestampAsDateTimeOffset);
set
{
CreatedOnTimestampAsDateTimeOffset = value.ToDateTimeOffset();
CreatedOnAsString = new Rfc3339SerializableDateTimeOffset(value.ToBelgianDateTimeOffset()).ToString();
}
}

public BuildingLatestItem()
{ }
}

public sealed class BuildingLatestItemConfiguration : IEntityTypeConfiguration<BuildingLatestItem>
{
public void Configure(EntityTypeBuilder<BuildingLatestItem> builder)
{
const string tableName = "building_latest_items";

builder
.ToTable(tableName, Schema.Integration) // to schema per type
.HasKey(x => x.BuildingPersistentLocalId);

builder.Property(x => x.BuildingPersistentLocalId).HasColumnName("building_persistent_local_id");
builder.Property(x => x.Status).HasColumnName("status");
builder.Property(x => x.OsloStatus).HasColumnName("oslo_status");
builder.Property(x => x.GeometryMethod).HasColumnName("geometry_method");
builder.Property(x => x.Geometry).HasColumnName("geometry");
builder.Property(x => x.NisCode).HasColumnName("nis_code");
builder.Property(x => x.IsRemoved).HasColumnName("is_removed");
builder.Property(x => x.PuriId).HasColumnName("puri_id");
builder.Property(x => x.Namespace).HasColumnName("namespace");
builder.Property(x => x.VersionAsString).HasColumnName("version_as_string");
builder.Property(BuildingLatestItem.VersionTimestampBackingPropertyName).HasColumnName("version_timestamp");
builder.Property(x => x.CreatedOnAsString).HasColumnName("created_on_as_string");
builder.Property(BuildingLatestItem.CreatedTimestampBackingPropertyName).HasColumnName("created_on_timestamp");

builder.Ignore(x => x.VersionTimestamp);
builder.Ignore(x => x.CreatedOnTimestamp);

builder.HasIndex(x => x.Status);
builder.HasIndex(x => x.OsloStatus);
builder.HasIndex(x => x.IsRemoved);
builder.HasIndex(x => x.NisCode);
builder.HasIndex(x => x.Geometry).HasMethod("GIST");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace BuildingRegistry.Projections.Integration.Building.LatestItem
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Be.Vlaanderen.Basisregisters.ProjectionHandling.Connector;

public static class BuildingLatestItemExtensions
{
public static async Task<BuildingLatestItem> FindAndUpdateBuilding(this IntegrationContext context,
int buildingPersistentLocalId,
Action<BuildingLatestItem> updateFunc,
CancellationToken ct)
{
var building = await context
.BuildingLatestItems
.FindAsync(buildingPersistentLocalId, cancellationToken: ct);

if (building == null)
throw DatabaseItemNotFound(buildingPersistentLocalId);

updateFunc(building);

return building;
}

private static ProjectionItemNotFoundException<BuildingLatestItemProjections> DatabaseItemNotFound(int buildingPersistentLocalId)
=> new ProjectionItemNotFoundException<BuildingLatestItemProjections>(buildingPersistentLocalId.ToString());
}
}
Loading

0 comments on commit 5a5b367

Please sign in to comment.