-
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 #72 from GeneriekPublicatiePlatformWoo/58-Informat…
…iecategorieën-ophalen-uit-ODRC 58 informatiecategorieën ophalen uit odrc
- Loading branch information
Showing
5 changed files
with
69 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace ODPC.Apis.Odrc | ||
{ | ||
public class PagedResponseModel<T> | ||
{ | ||
public List<T> results { get; set; } | ||
public int Count { get; set; } | ||
public string? Next { get; set; } | ||
public string? Previous { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.ComponentModel; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ODPC.Apis.Odrc | ||
{ | ||
public class WaardelijstResponseModel | ||
{ | ||
[JsonPropertyName("uuid")] | ||
public required string Id { get; set; } | ||
[JsonPropertyName("naam")] | ||
public required string Name { get; set; } | ||
} | ||
} |
13 changes: 9 additions & 4 deletions
13
ODPC.Server/Features/WaardeLijstenOverzicht/WaardelijstViewModel.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,10 +1,15 @@ | ||
namespace ODPC.Features.WaardeLijstenOverzicht | ||
using System.ComponentModel; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace ODPC.Features.WaardeLijstenOverzicht | ||
{ | ||
public class WaardelijstViewModel | ||
public class WaardelijstViewModel | ||
{ | ||
|
||
public required string Id { get; set; } | ||
|
||
public required string Name { get; set; } | ||
public required string Type { get; set; } | ||
|
||
public string Type { get; set; } = "INFORMATIECATEGORIE"; //tijdelijk. als de andere categorien ook uit het odrc gehaald worden, zullen de waardelijsten volledig gesplitst worden | ||
} | ||
} |
49 changes: 36 additions & 13 deletions
49
ODPC.Server/Features/WaardeLijstenOverzicht/WaardelijstenController.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,24 +1,47 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System.Text.Json; | ||
using System.Xml.Linq; | ||
using Microsoft.AspNetCore.Mvc; | ||
using ODPC.Apis.Odrc; | ||
using ODPC.Authentication; | ||
using ODPC.Config; | ||
using ODPC.Features.Publicaties; | ||
|
||
namespace ODPC.Features.WaardeLijstenOverzicht | ||
{ | ||
[Route("api/v1/[controller]")] | ||
[ApiController] | ||
public class WaardelijstenController : ControllerBase | ||
public class WaardelijstenController(OdpUser user, IOdrcClientFactory clientFactory) : ControllerBase | ||
{ | ||
[HttpGet] | ||
public IEnumerable<WaardelijstViewModel> Get() | ||
public async Task<IEnumerable<WaardelijstViewModel>> GetAsync() | ||
{ | ||
//hoe de waardelijsten api eruit komt te zien is nog onbekend. mogelijk wordt dit tzt losse endpoints per soort lijst, mogelijk worden de id's url's, mogelijk verschilt het model per soort lijst.... | ||
//gezien alle onbekendheden kiezen we even voor een zo simpel mogelijke start opzet | ||
return new WaardelijstViewModel[] { | ||
new() { Id = "d3da5277-ea07-4921-97b8-e9a181390c76", Name="arbeidsomstandigheden", Type="THEMA" }, | ||
new() { Id = "f1e4632d-9c71-4ea4-9048-a5665671bbe4", Name="wet of algemeen bindend voorschrift", Type="INFORMATIECATEGORIE" }, | ||
new() { Id = "066241fe-7f39-41da-8efb-a702ef32b7d0", Name = "afval", Type="THEMA" }, | ||
new() { Id = "8f939b51-dad3-436d-a5fa-495b42317d64", Name = "Organisatie 2", Type="ORGANISATIE" }, | ||
new() { Id = "5c14e7e2-00a2-4990-adbb-7290cd89fb6e", Name = "Organisatie 3", Type="ORGANISATIE" }, | ||
new() { Id = "0e7a0023-423a-421a-8700-359232fef584", Name = "europese zaken", Type="THEMA" } | ||
}; | ||
//infocategorien ophalen uit het ODRC | ||
|
||
//user en audit log handeling meegeven is misschien nog niet nodig, maar doet geen kwaad | ||
var client = clientFactory.Create(user, "Waardelijsten ophalen"); | ||
|
||
var response = await client.GetAsync("/api/v1/informatiecategorieen/", new CancellationToken()); | ||
|
||
response.EnsureSuccessStatusCode(); | ||
|
||
var responseBody = await response.Content.ReadAsStringAsync(); | ||
|
||
var deserializedResponse = JsonSerializer.Deserialize<PagedResponseModel<WaardelijstResponseModel>>(responseBody, JsonSerialization.Options); | ||
|
||
var informatiecategorieen = deserializedResponse?.results ?? []; | ||
|
||
var waardelijstenViewModel = informatiecategorieen.Select(x=> new WaardelijstViewModel { Id = x.Id, Name = x.Name}).ToList(); | ||
|
||
|
||
//nog wat dummy data toevoegen van andersoortige waardelijsten | ||
waardelijstenViewModel.Add(new WaardelijstViewModel() { Id = "d3da5277-ea07-4921-97b8-e9a181390c76", Name = "arbeidsomstandigheden", Type = "THEMA" }); | ||
waardelijstenViewModel.Add(new WaardelijstViewModel() { Id = "066241fe-7f39-41da-8efb-a702ef32b7d0", Name = "afval", Type = "THEMA" }); | ||
waardelijstenViewModel.Add(new WaardelijstViewModel() { Id = "8f939b51-dad3-436d-a5fa-495b42317d64", Name = "Organisatie 2", Type="ORGANISATIE" }); | ||
waardelijstenViewModel.Add(new WaardelijstViewModel() { Id = "5c14e7e2-00a2-4990-adbb-7290cd89fb6e", Name = "Organisatie 3", Type = "ORGANISATIE" }); | ||
waardelijstenViewModel.Add(new WaardelijstViewModel() { Id = "0e7a0023-423a-421a-8700-359232fef584", Name = "europese zaken", Type = "THEMA" }); | ||
|
||
return waardelijstenViewModel; | ||
} | ||
|
||
} | ||
} |