forked from tolbier/mastery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmastery.ex
More file actions
52 lines (46 loc) · 1.5 KB
/
Copy pathmastery.ex
File metadata and controls
52 lines (46 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
defmodule Mastery do
alias Mastery.Boundary.{QuizSession, QuizManager, Proctor}
alias Mastery.Boundary.{TemplateValidator, QuizValidator}
alias Mastery.Core.Quiz
@persistence_fn Application.compile_env(:mastery, :persistence_fn)
def build_quiz(fields) do
with :ok <- QuizValidator.errors(fields),
:ok <- GenServer.call(QuizManager, {:build_quiz, fields}),
do: :ok,
else: (error -> error)
end
def add_template(title, fields) do
with :ok <- TemplateValidator.errors(fields),
:ok <- GenServer.call(QuizManager, {:add_template, title, fields}),
do: :ok,
else: (error -> error)
end
def take_quiz(title, email) do
with %Quiz{} = quiz <- QuizManager.lookup_quiz_by_title(title),
{:ok, _} <- QuizSession.take_quiz(quiz, email) do
{title, email}
else
error -> error
end
end
def select_question(name) do
QuizSession.select_question(name)
end
def answer_question(name, answer, persistence_fn \\ @persistence_fn) do
QuizSession.answer_question(name, answer, persistence_fn)
end
def schedule_quiz(quiz, templates, start_at, end_at, notify_pid \\ nil) do
with :ok <- QuizValidator.errors(quiz),
true <- Enum.all?(templates, &(:ok == TemplateValidator.errors(&1))),
:ok <-
Proctor.schedule_quiz(
quiz,
templates,
start_at,
end_at,
notify_pid
),
do: :ok,
else: (error -> error)
end
end