Skip to content

Commit

Permalink
Endpoints for kartverket testdata
Browse files Browse the repository at this point in the history
  • Loading branch information
larsolavk committed Jan 2, 2025
1 parent 7875744 commit 6f142ac
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TResponse> GetDefault<TResponse>(string path) where TResponse : class, new()
{
EnsureDirectory(path);
Expand All @@ -13,7 +19,7 @@ public abstract class FileStore
return new TResponse();

await using var fileStream = File.OpenRead(file);
var data = await JsonSerializer.DeserializeAsync<TResponse>(fileStream);
var data = await JsonSerializer.DeserializeAsync<TResponse>(fileStream, SerializerOptions);

return data ?? new TResponse();
}
Expand All @@ -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<TResponse>(fileStream);
var data = await JsonSerializer.DeserializeAsync<TResponse>(fileStream, SerializerOptions);

return data ?? new TResponse();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace oed_testdata.Server.Infrastructure.TestdataStore.Kartverket;

public interface IKartverketStore
{
public Task<KartverketResponse> GetProperties(int partyId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace oed_testdata.Server.Infrastructure.TestdataStore.Kartverket
{
public class KartverketFileStore(ILogger<KartverketFileStore> logger) : FileStore, IKartverketStore
{
private const string BasePath = "./Testdata/Json/Kartverket";

public async Task<KartverketResponse> GetProperties(int partyId)
{
var response = await GetForParty<KartverketResponse>(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<KartverketResponse>(BasePath);

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
namespace oed_testdata.Server.Infrastructure.TestdataStore.Kartverket
{
public class KartverketResponse
{
public PropertyRights PropertyRights { get; set; }
}

public class PropertyRights
{
public IEnumerable<Property> Properties { get; set; }

public IEnumerable<PropertyWithRights> 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<Right> 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; }
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +12,7 @@ public static IServiceCollection AddTestdataStore(this IServiceCollection servic
return services
.AddTransient<IEstateStore, EstateFileStore>()
.AddTransient<IBankStore, BankFileStore>()
.AddTransient<ISvvStore, SvvFileStore>();
.AddTransient<ISvvStore, SvvFileStore>()
.AddTransient<IKartverketStore, KartverketFileStore>();
}
}
Original file line number Diff line number Diff line change
@@ -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<BankFileStore> logger) : FileStore, ISvvStore
public class SvvFileStore(ILogger<SvvFileStore> logger) : FileStore, ISvvStore
{
private const string BasePath = "./Testdata/Json/Svv";

public async Task<SvvResponse> GetVehicles(int partyId)
{
EnsureDirectory(BasePath);

var response = await GetForParty<SvvResponse>(BasePath, partyId);
if (response is not null)
{
Expand Down
8 changes: 2 additions & 6 deletions src/oed-testdata.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -75,9 +73,7 @@
}

app.MapBasicAuthenticationEndpoints();
app.MapEstateEndpoints();
app.MapBankEndpoints();
app.MapSvvEndpoints();
app.MapTestdataEndpoints();
app.MapOedInstanceEndpoints();
app.MapCloudEventEndpoints();

Expand Down
21 changes: 21 additions & 0 deletions src/oed-testdata.Server/Testdata/Json/Kartverket/default.json
Original file line number Diff line number Diff line change
@@ -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": []
}
}
33 changes: 33 additions & 0 deletions src/oed-testdata.Server/Testdata/Kartverket/KartverketEndpoints.cs
Original file line number Diff line number Diff line change
@@ -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<IResult> 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);
}
}
18 changes: 18 additions & 0 deletions src/oed-testdata.Server/Testdata/WebApplicationExtensions.cs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 6f142ac

Please sign in to comment.