Search⌘ K
AI Features

Adding More Functionality to the QuizManager

Explore how to extend the QuizManager by adding templates, supporting fetches, and creating a cleaner API using GenServer in Elixir. Understand how to handle state updates and isolate process logic to improve interaction with the core application components.

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:

C++
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 :ok to the user and set the new ...