Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FluentValidation to handle miniLcm api validation #1236

Closed
4 tasks done
hahn-kev opened this issue Nov 14, 2024 · 4 comments
Closed
4 tasks done

Use FluentValidation to handle miniLcm api validation #1236

hahn-kev opened this issue Nov 14, 2024 · 4 comments
Assignees
Labels
📖 MiniLcm issues related to miniLcm library code, includes fwdat bridge and lcmCrdt
Milestone

Comments

@hahn-kev
Copy link
Collaborator

hahn-kev commented Nov 14, 2024

We need a clear and consise way to validate requests for miniLcm, a great library for this is FluentValidation, I'd like to see that integrated, to start with the following can be validated:

  • Creating an entry with a sense that has an EntryId not matching it's parent is invalid (an empty/null id is fine)
  • Similar for complex forms, the expected property must match it's parent entry
  • Update and Create APIs should reject input with a deleted date set
  • Validation based on the current state, EG circular references

Examples can be found here https://github.com/sillsdev/languageforge-lexbox/tree/develop/backend/FwLite/MiniLcm/Validators

For now this validation is not data integrity based, but ensuring required fields are provided that sort of thing. Validation should follow Fieldworks as closely as we can.

@hahn-kev hahn-kev added the 💻 FW Lite issues related to the fw lite application, not miniLcm or crdt related label Nov 14, 2024
@hahn-kev hahn-kev added this to the FW Lite PoC milestone Nov 14, 2024
@hahn-kev hahn-kev added 📖 MiniLcm issues related to miniLcm library code, includes fwdat bridge and lcmCrdt and removed 💻 FW Lite issues related to the fw lite application, not miniLcm or crdt related labels Dec 6, 2024
@hahn-kev hahn-kev modified the milestones: FW Lite PoC, v3 Dec 6, 2024
@rmunn
Copy link
Contributor

rmunn commented Jan 5, 2025

  • Validation based on the current state, EG circular references

@hahn-kev Could you clarify this one a little?

@hahn-kev
Copy link
Collaborator Author

hahn-kev commented Jan 6, 2025

Yeah, for example an entry can't reference itself as a complex form, that sort of thing.

@rmunn
Copy link
Contributor

rmunn commented Jan 6, 2025

So, something like this then:

    public EntryValidator()
    {
        // ...
        RuleForEach(e => e.Components).Must(NotBeSelfReference);
        RuleForEach(e => e.Components).Must(HaveCorrectEntryReference);
    }

    private bool NotBeSelfReference(Entry entry, ComplexFormComponent component)
    {
        return component.ComponentEntryId != entry.Id;
    }

    private bool HaveCorrectEntryReference(Entry entry, ComplexFormComponent component)
    {
        return component.ComplexFormEntryId == entry.Id;
    }

@rmunn
Copy link
Contributor

rmunn commented Jan 10, 2025

With PR #1344 merged, I believe this is completed. Closing. @hahn-kev - Please reopen if there's more work to be done on this.

@rmunn rmunn closed this as completed Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📖 MiniLcm issues related to miniLcm library code, includes fwdat bridge and lcmCrdt
Projects
None yet
Development

No branches or pull requests

2 participants