-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: or-2031 registreer inschrijving when adding kbo verenigingen
- Loading branch information
Showing
117 changed files
with
5,728 additions
and
239 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
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
93 changes: 93 additions & 0 deletions
93
src/AssociationRegistry.Admin.Api/Magda/MagdaRegistreerInschrijvingService.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,93 @@ | ||
namespace AssociationRegistry.Admin.Api.Magda; | ||
|
||
using AssociationRegistry.Magda; | ||
using AssociationRegistry.Magda.Exceptions; | ||
using AssociationRegistry.Magda.Models; | ||
using AssociationRegistry.Magda.Repertorium.RegistreerInschrijving; | ||
using Framework; | ||
using Kbo; | ||
using Microsoft.Extensions.Logging; | ||
using ResultNet; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Vereniging; | ||
|
||
public class MagdaRegistreerInschrijvingService : IMagdaRegistreerInschrijvingService | ||
{ | ||
private readonly IMagdaCallReferenceRepository _magdaCallReferenceRepository; | ||
private readonly IMagdaClient _magdaClient; | ||
private readonly ILogger<MagdaRegistreerInschrijvingService> _logger; | ||
|
||
public MagdaRegistreerInschrijvingService( | ||
IMagdaCallReferenceRepository magdaCallReferenceRepository, | ||
IMagdaClient magdaClient, | ||
ILogger<MagdaRegistreerInschrijvingService> logger) | ||
{ | ||
_magdaCallReferenceRepository = magdaCallReferenceRepository; | ||
_magdaClient = magdaClient; | ||
_logger = logger; | ||
} | ||
|
||
public async Task<Result> RegistreerInschrijving( | ||
KboNummer kboNummer, | ||
CommandMetadata metadata, | ||
CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
var reference = await CreateReference( | ||
_magdaCallReferenceRepository, | ||
metadata.Initiator, | ||
metadata.CorrelationId, | ||
kboNummer, | ||
cancellationToken); | ||
|
||
var response = await _magdaClient.RegistreerInschrijving(kboNummer, reference); | ||
|
||
var uitzonderingen = response?.Body?.RegistreerInschrijvingResponse?.Repliek.Antwoorden.Antwoord.Uitzonderingen; | ||
|
||
_logger.LogInformation( | ||
"Uitzondering bij het aanroepen van de Magda GeefOnderneming service voor KBO-nummer {KboNummer}: " + | ||
"\nFouten:\n'{Uitzonderingen}'" + | ||
"\nWaarschuwingen:\n'{Waarschuwingen}'" + | ||
"\nInformatie:\n'{Informatie}'", | ||
kboNummer, | ||
uitzonderingen?.ConcatenateUitzonderingen(separator: "\n", UitzonderingTypeType.FOUT), | ||
uitzonderingen?.ConcatenateUitzonderingen(separator: "\n", UitzonderingTypeType.WAARSCHUWING), | ||
uitzonderingen?.ConcatenateUitzonderingen(separator: "\n", UitzonderingTypeType.INFORMATIE)); | ||
|
||
|
||
return response?.Body?.RegistreerInschrijvingResponse?.Repliek.Antwoorden.Antwoord.Inhoud.Resultaat.Value == ResultaatEnumType.Item1 ? Result.Success() : Result.Failure(); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new MagdaException( | ||
message: "Er heeft zich een fout voorgedaan bij het aanroepen van de Magda RegistreerInschrijvingDienst.", e); | ||
} | ||
} | ||
|
||
private static async Task<MagdaCallReference> CreateReference( | ||
IMagdaCallReferenceRepository repository, | ||
string initiator, | ||
Guid correlationId, | ||
string opgevraagdOnderwerp, | ||
CancellationToken cancellationToken) | ||
{ | ||
var magdaCallReference = new MagdaCallReference | ||
{ | ||
Reference = Guid.NewGuid(), | ||
CalledAt = DateTimeOffset.UtcNow, | ||
Initiator = initiator, | ||
OpgevraagdeDienst = "RegistreerInschrijvingDienst-02.01", | ||
Context = "Registreer inschrijving voor vereniging met rechtspersoonlijkheid", | ||
AanroependeDienst = "Verenigingsregister Beheer Api", | ||
CorrelationId = correlationId, | ||
OpgevraagdOnderwerp = opgevraagdOnderwerp, | ||
}; | ||
|
||
await repository.Save(magdaCallReference, cancellationToken); | ||
|
||
return magdaCallReference; | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
src/AssociationRegistry.Admin.Api/Verenigingen/KboSync/KboSyncHistoriekController.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,60 @@ | ||
namespace AssociationRegistry.Admin.Api.Verenigingen.KboSync; | ||
|
||
using Be.Vlaanderen.Basisregisters.Api; | ||
using Be.Vlaanderen.Basisregisters.Api.Exceptions; | ||
using Historiek.Examples; | ||
using Infrastructure.Swagger.Annotations; | ||
using Marten; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using ResponseModels; | ||
using Schema.KboSync; | ||
using Swashbuckle.AspNetCore.Filters; | ||
using System.Threading.Tasks; | ||
using ProblemDetails = Be.Vlaanderen.Basisregisters.BasicApiProblem.ProblemDetails; | ||
|
||
[ApiVersion("1.0")] | ||
[AdvertiseApiVersions("1.0")] | ||
[ApiRoute("verenigingen")] | ||
[ApiExplorerSettings(IgnoreApi = true)] | ||
[Authorize(Policy = Program.SuperAdminPolicyName)] | ||
public class KboSyncHistoriekController : ApiController | ||
{ | ||
private readonly KboSyncHistoriekResponseMapper _mapper; | ||
|
||
public KboSyncHistoriekController(KboSyncHistoriekResponseMapper mapper) | ||
{ | ||
_mapper = mapper; | ||
} | ||
|
||
/// <summary> | ||
/// Vraag de historiek van de KBO sync op. | ||
/// </summary> | ||
/// <param name="documentStore"></param> | ||
/// <param name="problemDetailsHelper"></param> | ||
/// <response code="200">De historiek van de KBO sync</response> | ||
/// <response code="500">Er is een interne fout opgetreden.</response> | ||
[HttpGet("kbo/historiek")] | ||
[SwaggerResponseExample(StatusCodes.Status200OK, typeof(HistoriekResponseExamples))] | ||
[SwaggerResponseExample(StatusCodes.Status500InternalServerError, typeof(InternalServerErrorResponseExamples))] | ||
[ProducesResponseType(typeof(KboSyncHistoriekResponse), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] | ||
[ProducesJson] | ||
public async Task<IActionResult> GetKboSyncHistoriek( | ||
[FromServices] IDocumentStore documentStore, | ||
[FromServices] ProblemDetailsHelper problemDetailsHelper | ||
) | ||
{ | ||
await using var session = documentStore.LightweightSession(); | ||
|
||
var gebeurtenissen = await session | ||
.Query<BeheerKboSyncHistoriekGebeurtenisDocument>() | ||
.OrderByDescending(nameof(BeheerKboSyncHistoriekGebeurtenisDocument.Sequence)) | ||
.ToListAsync(); | ||
|
||
var response = _mapper.Map(gebeurtenissen); | ||
|
||
return Ok(response); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/AssociationRegistry.Admin.Api/Verenigingen/KboSync/KboSyncHistoriekResponseMapper.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,29 @@ | ||
namespace AssociationRegistry.Admin.Api.Verenigingen.KboSync; | ||
|
||
using Infrastructure.ConfigurationBindings; | ||
using ResponseModels; | ||
using Schema.KboSync; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
public class KboSyncHistoriekResponseMapper | ||
{ | ||
private readonly AppSettings _appSettings; | ||
|
||
public KboSyncHistoriekResponseMapper(AppSettings appSettings) | ||
{ | ||
_appSettings = appSettings; | ||
} | ||
|
||
public KboSyncHistoriekResponse Map(IEnumerable<BeheerKboSyncHistoriekGebeurtenisDocument> gebeurtenissen) | ||
=> new(gebeurtenissen.Select(Map).ToArray()); | ||
|
||
private static KboSyncHistoriekGebeurtenisResponse Map(BeheerKboSyncHistoriekGebeurtenisDocument gebeurtenisDocument) | ||
=> new() | ||
{ | ||
Kbonummer = gebeurtenisDocument.Kbonummer, | ||
VCode = gebeurtenisDocument.VCode, | ||
Beschrijving = gebeurtenisDocument.Beschrijving, | ||
Tijdstip = gebeurtenisDocument.Tijdstip, | ||
}; | ||
} |
24 changes: 24 additions & 0 deletions
24
...stry.Admin.Api/Verenigingen/KboSync/ResponseModels/KboSyncHistoriekGebeurtenisResponse.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,24 @@ | ||
namespace AssociationRegistry.Admin.Api.Verenigingen.KboSync.ResponseModels; | ||
|
||
using System.Runtime.Serialization; | ||
|
||
/// <summary>Een gebeurtenis van een vereniging</summary> | ||
[DataContract] | ||
public class KboSyncHistoriekGebeurtenisResponse | ||
{ | ||
/// <summary>Het KBO nummer waarop de gebeurtenis plaatsvond</summary> | ||
[DataMember(Name = "kbonummer")] | ||
public string Kbonummer { get; set; } = null!; | ||
|
||
/// <summary>De unieke identificatie code van deze vereniging</summary> | ||
[DataMember(Name = "vCode")] | ||
public string VCode { get; init; } = null!; | ||
|
||
/// <summary>De beschrijving van de gebeurtenis</summary> | ||
[DataMember(Name = "beschrijving")] | ||
public string Beschrijving { get; set; } = null!; | ||
|
||
/// <summary>Het tijdstip waarop de gebeurtenis plaatsvond</summary> | ||
[DataMember(Name = "tijdstip")] | ||
public string Tijdstip { get; set; } = null!; | ||
} |
14 changes: 14 additions & 0 deletions
14
...ciationRegistry.Admin.Api/Verenigingen/KboSync/ResponseModels/KboSyncHistoriekResponse.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,14 @@ | ||
namespace AssociationRegistry.Admin.Api.Verenigingen.KboSync.ResponseModels; | ||
|
||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Runtime.Serialization; | ||
|
||
/// <summary>Alle gebeurtenissen van deze vereniging</summary> | ||
[DataContract] | ||
public class KboSyncHistoriekResponse : ReadOnlyCollection<KboSyncHistoriekGebeurtenisResponse> | ||
{ | ||
public KboSyncHistoriekResponse(IList<KboSyncHistoriekGebeurtenisResponse> gebeurtenissen) : base(gebeurtenissen) | ||
{ | ||
} | ||
} |
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
Oops, something went wrong.