-
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-1972 validate startdatum before dupplicate check
- Loading branch information
1 parent
2876d56
commit 5970558
Showing
120 changed files
with
374 additions
and
190 deletions.
There are no files selected for viewing
43 changes: 28 additions & 15 deletions
43
...Registry.Admin.Api/Verenigingen/Registreer/Afdeling/RegistreerAfdelingRequestValidator.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,51 +1,64 @@ | ||
// ReSharper disable ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract | ||
|
||
namespace AssociationRegistry.Admin.Api.Verenigingen.Registreer.Afdeling; | ||
|
||
using System.Linq; | ||
using Common; | ||
using Infrastructure.Validation; | ||
using FluentValidation; | ||
using Framework; | ||
using RequestModels; | ||
using System; | ||
using Vereniging.Exceptions; | ||
|
||
public class RegistreerAfdelingRequestValidator : AbstractValidator<RegistreerAfdelingRequest> | ||
{ | ||
public RegistreerAfdelingRequestValidator() | ||
private readonly IClock _clock; | ||
|
||
public RegistreerAfdelingRequestValidator(IClock clock) | ||
{ | ||
_clock = clock; | ||
this.RequireNotNullOrEmpty(request => request.Naam); | ||
|
||
this.RequireValidKboNummer(request => request.KboNummerMoedervereniging); | ||
|
||
RuleFor(request => request.Locaties) | ||
.Must(ToeTeVoegenLocatieValidator.NotHaveDuplicates) | ||
.WithMessage("Identieke locaties zijn niet toegelaten."); | ||
.Must(ToeTeVoegenLocatieValidator.NotHaveDuplicates) | ||
.WithMessage("Identieke locaties zijn niet toegelaten."); | ||
|
||
RuleFor(request => request.Locaties) | ||
.Must(ToeTeVoegenLocatieValidator.NotHaveMultipleCorrespondentieLocaties) | ||
.WithMessage("Er mag maximum één correspondentie locatie opgegeven worden."); | ||
.Must(ToeTeVoegenLocatieValidator.NotHaveMultipleCorrespondentieLocaties) | ||
.WithMessage("Er mag maximum één correspondentie locatie opgegeven worden."); | ||
|
||
RuleFor(request => request.Locaties) | ||
.Must(ToeTeVoegenLocatieValidator.NotHaveMultiplePrimairelocaties) | ||
.WithMessage("Er mag maximum één primaire locatie opgegeven worden."); | ||
.Must(ToeTeVoegenLocatieValidator.NotHaveMultiplePrimairelocaties) | ||
.WithMessage("Er mag maximum één primaire locatie opgegeven worden."); | ||
|
||
RuleFor(request => request.HoofdactiviteitenVerenigingsloket) | ||
.Must(NotHaveDuplicates) | ||
.WithMessage("Een waarde in de hoofdactiviteitenLijst mag slechts 1 maal voorkomen."); | ||
.Must(NotHaveDuplicates) | ||
.WithMessage("Een waarde in de hoofdactiviteitenLijst mag slechts 1 maal voorkomen."); | ||
|
||
RuleFor(request => request.Startdatum) | ||
.Must(BeBeforeToday) | ||
.When(r => r.Startdatum is not null) | ||
.WithMessage(new StartdatumMagNietInToekomstZijn().Message); | ||
|
||
RuleFor(request => request.Doelgroep) | ||
.SetValidator(new DoelgroepRequestValidator()!) | ||
.When(r => r.Doelgroep is not null); | ||
.SetValidator(new DoelgroepRequestValidator()!) | ||
.When(r => r.Doelgroep is not null); | ||
|
||
RuleForEach(request => request.Contactgegevens) | ||
.SetValidator(new ToeTeVoegenContactgegevenValidator()); | ||
.SetValidator(new ToeTeVoegenContactgegevenValidator()); | ||
|
||
RuleForEach(request => request.Locaties) | ||
.SetValidator(new ToeTeVoegenLocatieValidator()); | ||
.SetValidator(new ToeTeVoegenLocatieValidator()); | ||
|
||
RuleForEach(request => request.Vertegenwoordigers) | ||
.SetValidator(new ToeTeVoegenVertegenwoordigerValidator()); | ||
.SetValidator(new ToeTeVoegenVertegenwoordigerValidator()); | ||
} | ||
|
||
private bool BeBeforeToday(DateOnly? date) | ||
=> _clock.Today > date; | ||
|
||
private static bool NotHaveDuplicates(string[] values) | ||
=> values.Length == values.DistinctBy(v => v.ToLower()).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
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
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
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
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
Oops, something went wrong.