From d046bdcc24a583f2b0a1332716b3a2682c968d45 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Tue, 7 Jan 2025 15:30:01 -0500 Subject: [PATCH] Push two missing files --- .../Validators/PartOfSpeechValidator.cs | 19 +++++++++++++++++ .../Validators/WritingSystemValidator.cs | 21 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 backend/FwLite/MiniLcm/Validators/PartOfSpeechValidator.cs create mode 100644 backend/FwLite/MiniLcm/Validators/WritingSystemValidator.cs diff --git a/backend/FwLite/MiniLcm/Validators/PartOfSpeechValidator.cs b/backend/FwLite/MiniLcm/Validators/PartOfSpeechValidator.cs new file mode 100644 index 000000000..476c030b2 --- /dev/null +++ b/backend/FwLite/MiniLcm/Validators/PartOfSpeechValidator.cs @@ -0,0 +1,19 @@ +using FluentValidation; +using MiniLcm.Models; + +namespace MiniLcm.Validators; + +public class PartOfSpeechValidator : AbstractValidator +{ + 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); + } +} diff --git a/backend/FwLite/MiniLcm/Validators/WritingSystemValidator.cs b/backend/FwLite/MiniLcm/Validators/WritingSystemValidator.cs new file mode 100644 index 000000000..35ec4a7b7 --- /dev/null +++ b/backend/FwLite/MiniLcm/Validators/WritingSystemValidator.cs @@ -0,0 +1,21 @@ +using FluentValidation; +using MiniLcm.Models; +using SIL.WritingSystems; + +namespace MiniLcm.Validators; + +public class WritingSystemValidator : AbstractValidator +{ + 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); + } +}