Initial commit: there's still tons of base Phoenix boilerplate to remove, but the...
[tech-radar-editor.git] / web / models / radar_data_point.ex
1 defmodule TechRadarEditor.RadarDataPoint do
2 use TechRadarEditor.Web, :model
3
4 schema "radar_data_point" do
5 field :quadrant, :integer
6 field :cycle, :integer
7 field :is_new, :boolean, default: false
8 field :name, :string
9 field :description, :string
10
11 timestamps()
12 end
13
14 @doc """
15 Builds a changeset based on the `struct` and `params`.
16 """
17 def changeset(struct, params \\ %{}) do
18 struct
19 |> cast(params, [:quadrant, :cycle, :is_new, :name, :description])
20 |> validate_required([:quadrant, :cycle, :is_new, :name])
21 |> validate_inclusion(:quadrant, 1..4)
22 |> validate_inclusion(:cycle, 1..4)
23 end
24
25 def quadrants do
26 ["Tool", "Technique", "Platform", "Language"]
27 end
28
29 def cycles do
30 ["Adapt", "Trial", "Assess", "Hold"]
31 end
32
33
34 end