-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add integration database latest item projections
- Loading branch information
Showing
37 changed files
with
4,959 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
src/BuildingRegistry.Projections.Integration/Building/LatestItem/BuildingLatestItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
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 long IdempotenceKey { get; set; } | ||
|
||
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.Property(x => x.IdempotenceKey).HasColumnName("idempotence_key"); | ||
|
||
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"); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ldingRegistry.Projections.Integration/Building/LatestItem/BuildingLatestItemExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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, | ||
long position, | ||
Action<BuildingLatestItem> updateFunc, | ||
CancellationToken ct) | ||
{ | ||
var building = await context | ||
.BuildingLatestItems | ||
.FindAsync(buildingPersistentLocalId, cancellationToken: ct); | ||
|
||
if (building == null) | ||
throw DatabaseItemNotFound(buildingPersistentLocalId); | ||
|
||
building.IdempotenceKey = position; | ||
|
||
updateFunc(building); | ||
|
||
return building; | ||
} | ||
|
||
private static ProjectionItemNotFoundException<BuildingLatestItemProjections> DatabaseItemNotFound(int buildingPersistentLocalId) | ||
=> new ProjectionItemNotFoundException<BuildingLatestItemProjections>(buildingPersistentLocalId.ToString()); | ||
} | ||
} |
Oops, something went wrong.