Skip to content

Commit

Permalink
added grunnbeloep lookup from NAV
Browse files Browse the repository at this point in the history
  • Loading branch information
erlendoksvoll committed Dec 13, 2024
1 parent 1ac5ef5 commit 90c32a6
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/Dan.Plugin.Nav/Clients/NavClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
Expand All @@ -19,6 +19,7 @@ namespace Dan.Plugin.Nav.Clients;
public interface INavClient
{
Task<NavEmployeeQueryResponse> GetEmploymentHistory(EvidenceHarvesterRequest req);
Task<Grunnbeloep> GetCurrentGAmount();
}

public class NavClient(
Expand Down Expand Up @@ -46,6 +47,16 @@ public async Task<NavEmployeeQueryResponse> GetEmploymentHistory(EvidenceHarvest
return response;
}

public async Task<Grunnbeloep> GetCurrentGAmount()
{
var baseUrl = _settings.NavUrlGrunnbeloep;
const string path = "grunnbeloep";
var url = $"{baseUrl}{path}";
var request = new HttpRequestMessage(HttpMethod.Get, url);
var response = await MakeRequest<Grunnbeloep>(request);
return response;
}

private static HttpRequestMessage GetRequest<T>(string url, HttpMethod method, string mpToken, T body = null) where T : class
{
var uriBuilder = new UriBuilder(url);
Expand Down
4 changes: 3 additions & 1 deletion src/Dan.Plugin.Nav/Config/PluginConstants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Dan.Plugin.Nav.Config;
namespace Dan.Plugin.Nav.Config;

public static class PluginConstants
{
Expand All @@ -10,4 +10,6 @@ public static class PluginConstants
public const string EmploymentHistory = "EmploymentHistory";
public const string SourceName = "NAV";
public const string AltinnStudioAppsServiceContext = "Altinn Studio-apps";

public const string Grunnbeloep = "Grunnbeloep";
}
3 changes: 3 additions & 0 deletions src/Dan.Plugin.Nav/Dan.Plugin.Nav.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<None Include="local.settings.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Dan.Common" Version="1.6.0" />
<PackageReference Include="GraphQL.Client" Version="6.1.0" />
Expand Down
19 changes: 19 additions & 0 deletions src/Dan.Plugin.Nav/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ public List<EvidenceCode> GetEvidenceCodes()
.ToJson(Newtonsoft.Json.Formatting.Indented)
}
]
},
new EvidenceCode
{
EvidenceCodeName = PluginConstants.Grunnbeloep,
EvidenceSource = PluginConstants.SourceName,
ServiceContext = PluginConstants.AltinnStudioAppsServiceContext,
BelongsToServiceContexts = _belongsToAltinnStudioApps,
Description = "Gjeldende grunnbeløp fra NAV",
Values =
[
new EvidenceValue
{
EvidenceValueName = "default",
ValueType = EvidenceValueType.JsonSchema,
JsonSchemaDefintion = JsonSchema
.FromType<Grunnbeloep>()
.ToJson(Newtonsoft.Json.Formatting.Indented)
}
]
}
];
}
Expand Down
19 changes: 19 additions & 0 deletions src/Dan.Plugin.Nav/Models/Grunnbeloep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dan.Plugin.Nav.Models
{

public class Grunnbeloep
{
public string dato { get; set; }
public int grunnbeløp { get; set; }
public int grunnbeløpPerMåned { get; set; }
public int gjennomsnittPerÅr { get; set; }
public float omregningsfaktor { get; set; }
public string virkningstidspunktForMinsteinntekt { get; set; }
}
}
20 changes: 20 additions & 0 deletions src/Dan.Plugin.Nav/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

namespace Dan.Plugin.Nav;

Expand Down Expand Up @@ -63,4 +64,23 @@ private async Task<List<EvidenceValue>> GetEvidenceValuesAaReg(
ecb.AddEvidenceValue("default", response, PluginConstants.SourceName);
return ecb.GetEvidenceValues();
}

[Function(PluginConstants.Grunnbeloep)]
public async Task<HttpResponseData> GetGrunnbeloep(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestData req,
FunctionContext context)
{
return await EvidenceSourceResponse.CreateResponse(req,
() => GetEvidenceValuesGrunnbeloep());
}

private async Task<List<EvidenceValue>> GetEvidenceValuesGrunnbeloep()
{
var grunnbeloep = await navClient.GetCurrentGAmount();

var ecb = new EvidenceBuilder(evidenceSourceMetadata, PluginConstants.Grunnbeloep);
ecb.AddEvidenceValue("default", JsonConvert.SerializeObject(grunnbeloep), PluginConstants.SourceName, false);

return ecb.GetEvidenceValues();
}
}
2 changes: 2 additions & 0 deletions src/Dan.Plugin.Nav/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class Settings
public int SafeHttpClientTimeout { get; set; }

public string NavUrl { get; set; }

public string NavUrlGrunnbeloep { get; set; }
}

0 comments on commit 90c32a6

Please sign in to comment.