Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

35 minimale publicatie versturen naar registratiecomponent #67

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ODPC.Server/Apis/Odrc/OdrcConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Globalization;

namespace ODPC.Apis.Odrc
{
public class OdrcConfig
{
public required string BaseUrl { get; set; }
public required string ApiKey { get; set; }

}
}
30 changes: 30 additions & 0 deletions ODPC.Server/Apis/Odrc/OrdcClientFactory.cs
nijmra marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Net.Http.Headers;
using Microsoft.Extensions.Options;
using ODPC.Authentication;

namespace ODPC.Apis.Odrc
{
public interface IOrdcClientFactory
nijmra marked this conversation as resolved.
Show resolved Hide resolved
{
HttpClient Create(OdpUser user, string handeling);
}

public class OrdcClientFactory(IHttpClientFactory httpClientFactory, IOptions<OdrcConfig> options) : IOrdcClientFactory
nijmra marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly IHttpClientFactory _httpClientFactory = httpClientFactory;
private readonly IOptions<OdrcConfig> _options = options;

public HttpClient Create(OdpUser user, string handeling)
{
var config = _options.Value;
var client = _httpClientFactory.CreateClient();
client.BaseAddress = new(config.BaseUrl);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Token", config.ApiKey); //dit doet nog niets. nog niet geimplementeerd aan odrc kant. nb nog niet duidelijk of dit de juiste manier zal zijn voor het meesturen van het token
client.DefaultRequestHeaders.Add("Audit-User-Id", user.Id); //dit doet nog niets. nog niet geimplementeerd aan odrc kant
client.DefaultRequestHeaders.Add("Audit-User-Display-Name", user.FullName); //dit doet nog niets. nog niet geimplementeerd aan odrc kant
client.DefaultRequestHeaders.Add("Audit-Toelichting", handeling); //dit doet nog niets. nog niet geimplementeerd aan odrc kant
return client;
}

}
}
12 changes: 12 additions & 0 deletions ODPC.Server/Config/JsonSerialization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json;

namespace ODPC.Config
{
public static class JsonSerialization
{
public static readonly JsonSerializerOptions Options = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
using Microsoft.AspNetCore.Mvc;
using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using ODPC.Apis.Odrc;
using ODPC.Authentication;
using ODPC.Config;

namespace ODPC.Features.Publicaties.PublicatieRegistreren
{
[ApiController]
public class PublicatieRegistrerenController : ControllerBase
public class PublicatieRegistrerenController(OdpUser user, IOrdcClientFactory clientFactory) : ControllerBase
nijmra marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly IOrdcClientFactory _clientFactory = clientFactory;

[HttpPost("api/v1/publicaties")]
public IActionResult Post(Publicatie publicatie)
public async Task<IActionResult> Post(Publicatie publicatie)
{
publicatie.Uuid = Guid.NewGuid();
publicatie.Registratiedatum = DateTime.Now;

//de mock laten we er nog even in totdat ook het ophalen van gegevens via het register verloopt
PublicatiesMock.Publicaties[publicatie.Uuid] = publicatie;
return Ok(publicatie);

var client = _clientFactory.Create(user, "Publicatie geregistreerd");

var response = await client.PostAsJsonAsync("/api/v1/publicaties/", publicatie, new CancellationToken());

response.EnsureSuccessStatusCode();

var responseBody = await response.Content.ReadAsStringAsync();

var viewModel = JsonSerializer.Deserialize<Publicatie>(responseBody, JsonSerialization.Options);

return Ok(viewModel);
}

}
}
5 changes: 5 additions & 0 deletions ODPC.Server/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using ODPC.Apis.Odrc;
using ODPC.Authentication;
using ODPC.Data;
using Serilog;
Expand Down Expand Up @@ -39,6 +40,10 @@

var connStr = $"Username={builder.Configuration["POSTGRES_USER"]};Password={builder.Configuration["POSTGRES_PASSWORD"]};Host={builder.Configuration["POSTGRES_HOST"]};Database={builder.Configuration["POSTGRES_DB"]};Port={builder.Configuration["POSTGRES_PORT"]}";
builder.Services.AddDbContext<OdpcDbContext>(opt => opt.UseNpgsql(connStr));
builder.Services.Configure<OdrcConfig>(builder.Configuration.GetSection("Odrc"));
builder.Services.AddScoped<IOrdcClientFactory, OrdcClientFactory>();
nijmra marked this conversation as resolved.
Show resolved Hide resolved



var app = builder.Build();

Expand Down
7 changes: 6 additions & 1 deletion ODPC.Server/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
"OIDC_NAME_CLAIM_TYPE": "",
"OIDC_ROLE_CLAIM_TYPE": "",
"OIDC_ID_CLAIM_TYPE": "",
"AllowedHosts": "*"
"AllowedHosts": "*",

"Odrc": {
"BaseUrl": "https://woo-publicaties.test.opengem.nl/",
"ApiKey": "..."
}
}