Validating Our Quizzes
Explore validating quiz data in Elixir by building dedicated validator modules. Understand how to handle state isolation and error management with GenServer while validating required and optional fields such as title and mastery. This lesson helps you create robust data checks using pattern matching and custom error responses.
We'll cover the following...
We'll cover the following...
We first need to validate a quiz. We are creating a module per validator, and only add models that take complex user data.
Declaring our module and some core functions
In /lib/mastery/boundary/quiz_validator.ex, we’ll write this code:
We have a core errors function that does the lion’s share of the work.
-
We have only two fields that have external input, an optional
:masteryfield and a required:titlefield. -
We pipe through those and return the responses. ...