Commit 093d35c8 authored by Piotr Baj's avatar Piotr Baj 🏡

Add price field to plans

parent b099058f
......@@ -7,6 +7,7 @@ defmodule Webapp.Plans.Plan do
field(:name, :string)
field(:ram, :integer)
field(:storage, :integer)
field(:price, :integer)
has_many(:machines, Webapp.Machines.Machine)
......@@ -16,8 +17,8 @@ defmodule Webapp.Plans.Plan do
@doc false
def changeset(plan, attrs) do
plan
|> cast(attrs, [:name, :storage, :ram, :cpu])
|> validate_required([:name, :storage, :ram, :cpu])
|> cast(attrs, [:name, :storage, :ram, :cpu, :price])
|> validate_required([:name, :storage, :ram, :cpu, :price])
|> unique_constraint(:name)
end
end
......@@ -14,6 +14,16 @@
<%= error_tag f, :name %>
</div>
<div class="field">
<%= label f, :price, class: "label" %>
<div>Price (monthly)</div>
<div class="control">
<%= number_input f, :price, class: "input" %>
</div>
<%= error_tag f, :price %>
</div>
<div class="field">
<%= label f, :storage, class: "label" %>
<div>Storage in gigabytes.</div>
......
......@@ -20,6 +20,7 @@
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Storage</th>
<th>Ram</th>
<th>Cpu</th>
......@@ -31,6 +32,7 @@
<%= for plan <- @plans do %>
<tr>
<td><%= link plan.name, to: Routes.admin_plan_path(@conn, :show, plan) %></td>
<td><%= plan.price %></td>
<td><%= plan.storage %></td>
<td><%= plan.ram %></td>
<td><%= plan.cpu %></td>
......
......@@ -28,6 +28,11 @@
<strong>Name:</strong>
<%= @plan.name %>
</li>
<li>
<strong>Price:</strong>
$<%= @plan.price %>
</li>
<li>
<strong>Storage:</strong>
......
......@@ -80,7 +80,7 @@
<span>
<strong>Price:</strong>
$999
$<%= plan.price %> / mo
</span>
</span>
</label>
......
defmodule Webapp.Repo.Migrations.AddPriceToPlan do
use Ecto.Migration
def change do
alter table(:plans) do
add(:price, :integer)
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment