-
-
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.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
backend/FwLite/MiniLcm/Validators/PartOfSpeechValidator.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,19 @@ | ||
using FluentValidation; | ||
using MiniLcm.Models; | ||
|
||
namespace MiniLcm.Validators; | ||
|
||
public class PartOfSpeechValidator : AbstractValidator<PartOfSpeech> | ||
{ | ||
public PartOfSpeechValidator() | ||
{ | ||
RuleFor(pos => pos.Id).Must(BeCanonicalGuid).When(pos => pos.Predefined); | ||
RuleFor(pos => pos.DeletedAt).Null(); | ||
RuleFor(pos => pos.Name).Required(); | ||
} | ||
|
||
private bool BeCanonicalGuid(Guid id) | ||
{ | ||
return CanonicalGuidsPartOfSpeech.CanonicalPosGuids.Contains(id); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/FwLite/MiniLcm/Validators/WritingSystemValidator.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,21 @@ | ||
using FluentValidation; | ||
using MiniLcm.Models; | ||
using SIL.WritingSystems; | ||
|
||
namespace MiniLcm.Validators; | ||
|
||
public class WritingSystemValidator : AbstractValidator<WritingSystem> | ||
{ | ||
public WritingSystemValidator() | ||
{ | ||
RuleFor(ws => ws.Abbreviation).NotNull().NotEmpty(); | ||
RuleFor(ws => ws.DeletedAt).Null(); | ||
RuleFor(ws => ws.Name).NotNull().NotEmpty(); | ||
RuleFor(ws => ws.WsId).Must(BeValidWsId); | ||
} | ||
|
||
private bool BeValidWsId(WritingSystemId wsId) | ||
{ | ||
return wsId.Code == "default" || wsId.Code == "__key" || IetfLanguageTag.IsValid(wsId.Code); | ||
} | ||
} |