Adding More Functionality to the QuizManager

Let's continue writing processes for our quiz manager.

Adding a template

That first call we made in the previous lesson is a little tricky, but the rest will look the same. Let’s add a template to lib/mastery/boundary/quiz_manager.ex:

Press + to interact
def handle_call(
{:add_template, quiz_title, template_fields}, _from,
quizzes
) do
new_quizzes = Map.update!(quizzes, quiz_title, fn quiz ->
Quiz.add_template(quiz, template_fields)
end)
{:reply, :ok, new_quizzes}
end

This callback uses the same technique to add templates to a quiz:

  • We invoke Quiz.add_template from our core and store that result to our map using Map.update.

  • We return ...

Get hands-on with 1400+ tech skills courses.