Skip to content

Commit

Permalink
Push two missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Jan 7, 2025
1 parent e5b02b7 commit d046bdc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions backend/FwLite/MiniLcm/Validators/PartOfSpeechValidator.cs
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 backend/FwLite/MiniLcm/Validators/WritingSystemValidator.cs
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);
}
}

0 comments on commit d046bdc

Please sign in to comment.