-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from GeneriekPublicatiePlatformWoo/39-informat…
…iecategorieen-toekennen 39 informatiecategorieen toekennen
- Loading branch information
Showing
43 changed files
with
566 additions
and
427 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
using System.ComponentModel; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ODPC.Apis.Odrc | ||
namespace ODPC.Apis.Odrc | ||
{ | ||
public class WaardelijstResponseModel | ||
{ | ||
[JsonPropertyName("uuid")] | ||
public required string Id { get; set; } | ||
[JsonPropertyName("naam")] | ||
public required string Name { get; set; } | ||
{ | ||
public required string Uuid { get; set; } | ||
public required string Naam { get; set; } | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
ODPC.Server/Authentication/OdpUser.cs → ODPC.Server/Authentication/OdpcUser.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
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,27 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using ODPC.Authentication; | ||
using ODPC.Data; | ||
|
||
namespace ODPC.Features | ||
{ | ||
public interface IGebruikerWaardelijstItemsService | ||
{ | ||
Task<IReadOnlyList<string>> GetAsync(CancellationToken token); | ||
} | ||
|
||
public class GebruikerWaardelijstItemsService(OdpcUser user, OdpcDbContext context) : IGebruikerWaardelijstItemsService | ||
{ | ||
public async Task<IReadOnlyList<string>> GetAsync(CancellationToken token) | ||
{ | ||
var groepIds = context.GebruikersgroepGebruikers | ||
.Where(x => x.GebruikerId == user.Id) | ||
.Select(x => x.GebruikersgroepUuid); | ||
|
||
return await context.GebruikersgroepWaardelijsten | ||
.Where(x => groepIds.Contains(x.GebruikersgroepUuid)) | ||
.Select(x => x.WaardelijstId) | ||
.Distinct() | ||
.ToListAsync(token); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...atures/Informatiecategorieen/AlleInformatiecategorieen/InformatiecategorieenController.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,28 @@ | ||
using System.Text.Json.Nodes; | ||
using Microsoft.AspNetCore.Mvc; | ||
using ODPC.Apis.Odrc; | ||
|
||
namespace ODPC.Features.Informatiecategorieen.AlleInformatiecategorieen | ||
{ | ||
[ApiController] | ||
public class InformatiecategorieenController(IOdrcClientFactory clientFactory) : ControllerBase | ||
{ | ||
[HttpGet("api/v1/informatiecategorieen")] | ||
public async Task<IActionResult> Get([FromQuery] string? page, CancellationToken token) | ||
{ | ||
//infocategorien ophalen uit het ODRC | ||
using var client = clientFactory.Create("Alle informatiecategorieen ophalen"); | ||
var json = await client.GetFromJsonAsync<PagedResponseModel<JsonNode>>("/api/v1/informatiecategorieen?page=" + page, token); | ||
if (json != null) | ||
{ | ||
json.Previous = GetPathAndQuery(json.Previous); | ||
json.Next = GetPathAndQuery(json.Next); | ||
} | ||
return Ok(json); | ||
} | ||
|
||
private static string? GetPathAndQuery(string? url) => Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uri) | ||
? uri.PathAndQuery | ||
: url; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...es/Informatiecategorieen/MijnInformatiecategorieen/MijnInformatiecategorieenController.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,38 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Text.Json.Nodes; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using ODPC.Apis.Odrc; | ||
|
||
namespace ODPC.Features.Informatiecategorieen.MijnInformatiecategorieen | ||
{ | ||
[ApiController] | ||
public class MijnInformatiecategorieenController(IOdrcClientFactory clientFactory, IGebruikerWaardelijstItemsService waardelijstItemsService) : ControllerBase | ||
{ | ||
[HttpGet("api/v1/mijn-informatiecategorieen")] | ||
public async IAsyncEnumerable<JsonObject> Get([EnumeratorCancellation] CancellationToken token) | ||
{ | ||
var categorieen = await waardelijstItemsService.GetAsync(token); | ||
|
||
if (categorieen.Count == 0) yield break; | ||
|
||
using var client = clientFactory.Create("Eigen informatiecategorieen ophalen"); | ||
var url = "api/v1/informatiecategorieen"; | ||
|
||
// omdat we zelf moeten filteren obv van de waardelijstitems waar de gebruiker toegang toe heeft, | ||
// kunnen we geen paginering gebruiker. we lopen door alle pagina's van de ODRC | ||
while (!string.IsNullOrWhiteSpace(url)) | ||
{ | ||
var page = await client.GetFromJsonAsync<PagedResponseModel<JsonObject>>(url, token) ?? new() { Results = [] }; | ||
foreach (var item in page.Results) | ||
{ | ||
if (item["uuid"]?.GetValue<string>() is string uuid && categorieen.Contains(uuid)) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
url = page?.Next; | ||
} | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
ODPC.Server/Features/Organisaties/AlleOrganisaties/OrganisatiesController.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,16 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using ODPC.Apis.Odrc; | ||
|
||
namespace ODPC.Features.Organisaties.AlleOrganisaties | ||
{ | ||
[ApiController] | ||
public class OrganisatiesController : ControllerBase | ||
{ | ||
[HttpGet("api/v1/organisaties")] | ||
public IActionResult Get([FromQuery] string? page) => Ok(new PagedResponseModel<WaardelijstResponseModel> | ||
{ | ||
Results = OrganisatiesMock.Organisaties.Values.ToList(), | ||
Count = OrganisatiesMock.Organisaties.Count, | ||
}); | ||
} | ||
} |
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,13 @@ | ||
using ODPC.Apis.Odrc; | ||
|
||
namespace ODPC.Features.Organisaties | ||
{ | ||
public class OrganisatiesMock | ||
{ | ||
public static readonly Dictionary<string, WaardelijstResponseModel> Organisaties = new WaardelijstResponseModel[] | ||
{ | ||
new() { Uuid = "8f939b51-dad3-436d-a5fa-495b42317d64", Naam = "Organisatie 2" }, | ||
new() { Uuid = "5c14e7e2-00a2-4990-adbb-7290cd89fb6e", Naam = "Organisatie 3" } | ||
}.ToDictionary(x => x.Uuid); | ||
} | ||
} |
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
37 changes: 20 additions & 17 deletions
37
ODPC.Server/Features/Publicaties/PublicatieRegistreren/PublicatieRegistrerenController.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 |
---|---|---|
@@ -1,37 +1,40 @@ | ||
using System.Text.Json; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc; | ||
using ODPC.Apis.Odrc; | ||
using ODPC.Authentication; | ||
using ODPC.Config; | ||
|
||
namespace ODPC.Features.Publicaties.PublicatieRegistreren | ||
{ | ||
[ApiController] | ||
public class PublicatieRegistrerenController(OdpUser user, IOdrcClientFactory clientFactory) : ControllerBase | ||
public class PublicatieRegistrerenController(IOdrcClientFactory clientFactory, IGebruikerWaardelijstItemsService waardelijstItemsService) : ControllerBase | ||
{ | ||
private readonly IOdrcClientFactory _clientFactory = clientFactory; | ||
|
||
[HttpPost("api/v1/publicaties")] | ||
public async Task<IActionResult> Post(Publicatie publicatie) | ||
public async Task<IActionResult> Post(Publicatie publicatie, CancellationToken token) | ||
{ | ||
publicatie.Uuid = Guid.NewGuid(); | ||
publicatie.Registratiedatum = DateTime.Now; | ||
var categorieen = await waardelijstItemsService.GetAsync(token); | ||
|
||
//de mock laten we er nog even in totdat ook het ophalen van gegevens via het register verloopt | ||
PublicatiesMock.Publicaties[publicatie.Uuid] = publicatie; | ||
if (publicatie.GekoppeldeInformatiecategorieen != null && publicatie.GekoppeldeInformatiecategorieen.Any(c => !categorieen.Contains(c))) | ||
{ | ||
ModelState.AddModelError(nameof(publicatie.GekoppeldeInformatiecategorieen), "Gebruiker is niet geautoriseerd voor deze informatiecategorieën"); | ||
return BadRequest(ModelState); | ||
} | ||
|
||
var client = _clientFactory.Create(user, "Publicatie geregistreerd"); | ||
var client = _clientFactory.Create("Publicatie geregistreerd"); | ||
var response = await client.PostAsJsonAsync("/api/v1/publicaties", publicatie, token); | ||
|
||
var response = await client.PostAsJsonAsync("/api/v1/publicaties", publicatie, new CancellationToken()); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
var responseBody = await response.Content.ReadAsStringAsync(); | ||
var viewModel = await response.Content.ReadFromJsonAsync<Publicatie>(token); | ||
|
||
var viewModel = JsonSerializer.Deserialize<Publicatie>(responseBody, JsonSerialization.Options); | ||
// TODO deze regel kan eraf als deze story is geimplementeerd: https://github.com/GeneriekPublicatiePlatformWoo/registratie-component/issues/48 | ||
viewModel!.GekoppeldeInformatiecategorieen = publicatie.GekoppeldeInformatiecategorieen; | ||
|
||
// TODO deze regel kan eraf als deze story is geimplementeerd: https://github.com/GeneriekPublicatiePlatformWoo/registratie-component/issues/49 | ||
viewModel!.Status = publicatie.Status; | ||
|
||
// TODO de mock laten we er nog even in totdat ook het ophalen van gegevens via het register verloopt: https://github.com/GeneriekPublicatiePlatformWoo/Openbaar-Documenten-Publicatie-Component/issues/68 | ||
PublicatiesMock.Publicaties[viewModel!.Uuid] = viewModel; | ||
|
||
return Ok(viewModel); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.