From 6f142acb48505b5e81b367e597d6a15cf49f14f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Olav=20Kj=C3=B8lstad?= Date: Thu, 2 Jan 2025 13:02:32 +0100 Subject: [PATCH] Endpoints for kartverket testdata --- .../Infrastructure/TestdataStore/FileStore.cs | 10 ++- .../Kartverket/IKartverketStore.cs | 6 ++ .../Kartverket/KartverketFileStore.cs | 21 ++++++ .../Kartverket/KartverketResponse.cs | 68 +++++++++++++++++++ .../ServiceCollectionExtensions.cs | 4 +- .../TestdataStore/Svv/SvvFileStore.cs | 8 +-- src/oed-testdata.Server/Program.cs | 8 +-- .../Testdata/Json/Kartverket/default.json | 21 ++++++ .../Kartverket/KartverketEndpoints.cs | 33 +++++++++ .../Testdata/WebApplicationExtensions.cs | 18 +++++ 10 files changed, 182 insertions(+), 15 deletions(-) create mode 100644 src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/IKartverketStore.cs create mode 100644 src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/KartverketFileStore.cs create mode 100644 src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/KartverketResponse.cs create mode 100644 src/oed-testdata.Server/Testdata/Json/Kartverket/default.json create mode 100644 src/oed-testdata.Server/Testdata/Kartverket/KartverketEndpoints.cs create mode 100644 src/oed-testdata.Server/Testdata/WebApplicationExtensions.cs diff --git a/src/oed-testdata.Server/Infrastructure/TestdataStore/FileStore.cs b/src/oed-testdata.Server/Infrastructure/TestdataStore/FileStore.cs index 875f4f0..ec4a973 100644 --- a/src/oed-testdata.Server/Infrastructure/TestdataStore/FileStore.cs +++ b/src/oed-testdata.Server/Infrastructure/TestdataStore/FileStore.cs @@ -4,6 +4,12 @@ namespace oed_testdata.Server.Infrastructure.TestdataStore; public abstract class FileStore { + private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + WriteIndented = true + }; + protected async Task GetDefault(string path) where TResponse : class, new() { EnsureDirectory(path); @@ -13,7 +19,7 @@ public abstract class FileStore return new TResponse(); await using var fileStream = File.OpenRead(file); - var data = await JsonSerializer.DeserializeAsync(fileStream); + var data = await JsonSerializer.DeserializeAsync(fileStream, SerializerOptions); return data ?? new TResponse(); } @@ -28,7 +34,7 @@ public abstract class FileStore if (file is null) return null; await using var fileStream = File.OpenRead(file); - var data = await JsonSerializer.DeserializeAsync(fileStream); + var data = await JsonSerializer.DeserializeAsync(fileStream, SerializerOptions); return data ?? new TResponse(); } diff --git a/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/IKartverketStore.cs b/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/IKartverketStore.cs new file mode 100644 index 0000000..458aadf --- /dev/null +++ b/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/IKartverketStore.cs @@ -0,0 +1,6 @@ +namespace oed_testdata.Server.Infrastructure.TestdataStore.Kartverket; + +public interface IKartverketStore +{ + public Task GetProperties(int partyId); +} \ No newline at end of file diff --git a/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/KartverketFileStore.cs b/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/KartverketFileStore.cs new file mode 100644 index 0000000..535ab18 --- /dev/null +++ b/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/KartverketFileStore.cs @@ -0,0 +1,21 @@ +namespace oed_testdata.Server.Infrastructure.TestdataStore.Kartverket +{ + public class KartverketFileStore(ILogger logger) : FileStore, IKartverketStore + { + private const string BasePath = "./Testdata/Json/Kartverket"; + + public async Task GetProperties(int partyId) + { + var response = await GetForParty(BasePath, partyId); + if (response is not null) + { + logger.LogInformation("Returning SPECIFIC property testdata for partyId [{partyId}]", partyId); + return response; + } + + logger.LogInformation("Returning DEFAULT property testdata for partyId [{partyId}]", partyId); + return await GetDefault(BasePath); + + } + } +} diff --git a/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/KartverketResponse.cs b/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/KartverketResponse.cs new file mode 100644 index 0000000..015318e --- /dev/null +++ b/src/oed-testdata.Server/Infrastructure/TestdataStore/Kartverket/KartverketResponse.cs @@ -0,0 +1,68 @@ +namespace oed_testdata.Server.Infrastructure.TestdataStore.Kartverket +{ + public class KartverketResponse + { + public PropertyRights PropertyRights { get; set; } + } + + public class PropertyRights + { + public IEnumerable Properties { get; set; } + + public IEnumerable PropertiesWithRights { get; set; } + } + + public class Property + { + public string Address { get; set; } + + public string City { get; set; } + + public string PostalCode { get; set; } + + // Eiendomsrett / Framfesterett (1,2,3) / Veirett / Borett / Leierett + public string Type { get; set; } + + // Kommunenavn + public string Municipality { get; set; } + + // Kommunenummer + public string MunicipalityNumber { get; set; } + + // Gårdsnummer + public string HoldingNumber { get; set; } + + // Bruksnummer + public string SubholdingNumber { get; set; } + + // Festenummer + public string LeaseNumber { get; set; } + + // Seksjonsnummer + public string SectionNumber { get; set; } + + // Eierandel i brøk + public string FractionOwnership { get; set; } + + // Is added from the "landbruk" integration + public bool IsAgriculture { get; set; } + } + + public class PropertyWithRights : Property + { + public List Rights { get; set; } + } + + public class Right + { + public string DocumentYear { get; set; } + + public string DocumentNumber { get; set; } + + public string OfficeNumber { get; set; } + + public string JudgementNumber { get; set; } + + public string JudgmentType { get; set; } + } +} diff --git a/src/oed-testdata.Server/Infrastructure/TestdataStore/ServiceCollectionExtensions.cs b/src/oed-testdata.Server/Infrastructure/TestdataStore/ServiceCollectionExtensions.cs index 1d549e9..944c9a0 100644 --- a/src/oed-testdata.Server/Infrastructure/TestdataStore/ServiceCollectionExtensions.cs +++ b/src/oed-testdata.Server/Infrastructure/TestdataStore/ServiceCollectionExtensions.cs @@ -1,5 +1,6 @@ using oed_testdata.Server.Infrastructure.TestdataStore.Bank; using oed_testdata.Server.Infrastructure.TestdataStore.Estate; +using oed_testdata.Server.Infrastructure.TestdataStore.Kartverket; using oed_testdata.Server.Infrastructure.TestdataStore.Svv; namespace oed_testdata.Server.Infrastructure.TestdataStore; @@ -11,6 +12,7 @@ public static IServiceCollection AddTestdataStore(this IServiceCollection servic return services .AddTransient() .AddTransient() - .AddTransient(); + .AddTransient() + .AddTransient(); } } \ No newline at end of file diff --git a/src/oed-testdata.Server/Infrastructure/TestdataStore/Svv/SvvFileStore.cs b/src/oed-testdata.Server/Infrastructure/TestdataStore/Svv/SvvFileStore.cs index 1066fe2..da1eba2 100644 --- a/src/oed-testdata.Server/Infrastructure/TestdataStore/Svv/SvvFileStore.cs +++ b/src/oed-testdata.Server/Infrastructure/TestdataStore/Svv/SvvFileStore.cs @@ -1,15 +1,11 @@ -using oed_testdata.Server.Infrastructure.TestdataStore.Bank; - -namespace oed_testdata.Server.Infrastructure.TestdataStore.Svv +namespace oed_testdata.Server.Infrastructure.TestdataStore.Svv { - public class SvvFileStore(ILogger logger) : FileStore, ISvvStore + public class SvvFileStore(ILogger logger) : FileStore, ISvvStore { private const string BasePath = "./Testdata/Json/Svv"; public async Task GetVehicles(int partyId) { - EnsureDirectory(BasePath); - var response = await GetForParty(BasePath, partyId); if (response is not null) { diff --git a/src/oed-testdata.Server/Program.cs b/src/oed-testdata.Server/Program.cs index 2297378..e91a76a 100644 --- a/src/oed-testdata.Server/Program.cs +++ b/src/oed-testdata.Server/Program.cs @@ -8,9 +8,7 @@ using oed_testdata.Server.Infrastructure.TestdataStore; using oed_testdata.Server.Oed; using oed_testdata.Server.Services; -using oed_testdata.Server.Testdata.Bank; -using oed_testdata.Server.Testdata.Estate; -using oed_testdata.Server.Testdata.Svv; +using oed_testdata.Server.Testdata; using Scalar.AspNetCore; var builder = WebApplication.CreateBuilder(args); @@ -75,9 +73,7 @@ } app.MapBasicAuthenticationEndpoints(); -app.MapEstateEndpoints(); -app.MapBankEndpoints(); -app.MapSvvEndpoints(); +app.MapTestdataEndpoints(); app.MapOedInstanceEndpoints(); app.MapCloudEventEndpoints(); diff --git a/src/oed-testdata.Server/Testdata/Json/Kartverket/default.json b/src/oed-testdata.Server/Testdata/Json/Kartverket/default.json new file mode 100644 index 0000000..8437772 --- /dev/null +++ b/src/oed-testdata.Server/Testdata/Json/Kartverket/default.json @@ -0,0 +1,21 @@ +{ + "propertyRights": { + "properties": [ + { + "address": "Pilestredet Park 4-H0102", + "city": "Oslo", + "postalCode": "0176", + "type": "Eiendomsrett", + "municipality": "Oslo", + "municipalityNumber": "0301", + "holdingNumber": "208", + "subholdingNumber": "951", + "leaseNumber": "0", + "sectionNumber": "1", + "fractionOwnership": "1/1", + "isAgriculture": false + } + ], + "propertiesWithRights": [] + } +} \ No newline at end of file diff --git a/src/oed-testdata.Server/Testdata/Kartverket/KartverketEndpoints.cs b/src/oed-testdata.Server/Testdata/Kartverket/KartverketEndpoints.cs new file mode 100644 index 0000000..7b64e03 --- /dev/null +++ b/src/oed-testdata.Server/Testdata/Kartverket/KartverketEndpoints.cs @@ -0,0 +1,33 @@ +using oed_testdata.Server.Infrastructure.TestdataStore.Kartverket; + +namespace oed_testdata.Server.Testdata.Kartverket; + +public static class KartverketEndpoints +{ + public static void MapKartverketEndpoints(this WebApplication app) + { + app + .MapGroup("/api/testdata/externalapi/kartverket/{instanceOwnerPartyId:int}/{instanceGuid:guid}") + .MapEndpoints() + .AllowAnonymous(); + } + + private static RouteGroupBuilder MapEndpoints(this RouteGroupBuilder group) + { + group.MapGet("/", GetProperties); + return group; + } + + private static async Task GetProperties( + int instanceOwnerPartyId, + HttpContext httpContext, + IKartverketStore store, + ILoggerFactory loggerFactory) + { + var logger = loggerFactory.CreateLogger(typeof(KartverketEndpoints)); + logger.LogInformation("Handling call for {path}", httpContext.Request.Path.Value); + + var resp = await store.GetProperties(instanceOwnerPartyId); + return Results.Ok(resp); + } +} \ No newline at end of file diff --git a/src/oed-testdata.Server/Testdata/WebApplicationExtensions.cs b/src/oed-testdata.Server/Testdata/WebApplicationExtensions.cs new file mode 100644 index 0000000..0602152 --- /dev/null +++ b/src/oed-testdata.Server/Testdata/WebApplicationExtensions.cs @@ -0,0 +1,18 @@ +using oed_testdata.Server.Testdata.Bank; +using oed_testdata.Server.Testdata.Estate; +using oed_testdata.Server.Testdata.Kartverket; +using oed_testdata.Server.Testdata.Svv; + +namespace oed_testdata.Server.Testdata +{ + public static class WebApplicationExtensions + { + public static void MapTestdataEndpoints(this WebApplication app) + { + app.MapEstateEndpoints(); + app.MapBankEndpoints(); + app.MapSvvEndpoints(); + app.MapKartverketEndpoints(); + } + } +}