diff --git a/lib/osuuspuutarha/harvest/parser.ex b/lib/osuuspuutarha/harvest/parser.ex new file mode 100644 index 0000000..7dcf946 --- /dev/null +++ b/lib/osuuspuutarha/harvest/parser.ex @@ -0,0 +1,49 @@ +defmodule Osuuspuutarha.Harvest.Parser do + def parse_plant(:lettuce) do + "Lettuce" + end + + def parse_plant(:tomato) do + "Tomato" + end + + def parse_plant(:cabbage) do + "Cabbage" + end + + def parse_plant(:pumpkin) do + "Pumpkin" + end + + def parse_plant(:zucchini) do + "Zucchini" + end + + def parse_plant(:cucumber) do + "Cucumber" + end + + def parse_plant(:melon) do + "Melon" + end + + def parse_plant(:sweet_corn) do + "Sweet Corn" + end + + def parse_plant(:bean) do + "Bean" + end + + def parse_plant(:parsnip) do + "Parsnip" + end + + def parse_plant(:carrot) do + "Carrot" + end + + def parse_plant(:beetroot) do + "Beetroot" + end +end diff --git a/lib/osuuspuutarha/harvest/yield.ex b/lib/osuuspuutarha/harvest/yield.ex index cee1c4a..4a0ffbe 100644 --- a/lib/osuuspuutarha/harvest/yield.ex +++ b/lib/osuuspuutarha/harvest/yield.ex @@ -5,7 +5,23 @@ defmodule Osuuspuutarha.Harvest.Yield do schema "yields" do field :amount, :decimal field :date, :date - field :plant, Ecto.Enum, values: [:salad, :carrot, :cabbage] + + field :plant, Ecto.Enum, + values: [ + :lettuce, + :tomato, + :cabbage, + :pumpkin, + :zucchini, + :cucumber, + :melon, + :sweet_corn, + :bean, + :parsnip, + :carrot, + :beetroot + ] + field :unit, Ecto.Enum, values: [:kg, :kpl] timestamps() diff --git a/lib/osuuspuutarha_web/live/yield_live/form_component.html.heex b/lib/osuuspuutarha_web/live/yield_live/form_component.html.heex index 498e015..03d19db 100644 --- a/lib/osuuspuutarha_web/live/yield_live/form_component.html.heex +++ b/lib/osuuspuutarha_web/live/yield_live/form_component.html.heex @@ -13,13 +13,27 @@ <%= label f, :date %>
<%= date_select f, :date, default: DateTime.now!("Etc/UTC"), builder: fn b -> %> - <%= b.(:day, []) %> / <%= b.(:month, options: [{"01", "1"}, "02", "03", "04", "05", {"06", "6"}, "07", "08", "09", "10", "11", "12"]) %> / <%= b.(:year, options: ["2023"]) %> + <%= b.(:day, []) %> / <%= b.(:month, options: [{"01", "1"}, {"02", "2"}, {"03", "3"}, {"04", "4"}, {"05", "5"}, {"06", "6"}, {"07", "7"}, {"08", "8"}, {"09", "9"}, "10", "11", "12"]) %> / <%= b.(:year, options: ["2023"]) %> <% end %> <%= error_tag f, :date %>
<%= label f, :plant %> - <%= select f, :plant, Ecto.Enum.values(Osuuspuutarha.Harvest.Yield, :plant), prompt: "Choose a value" %> + <%= select f, :plant, [ + "Lettuce": :lettuce, + "Tomato": :tomato, + "Cabbage": :cabbage, + "Pumpkin": :pumpkin, + "Zucchini": :zucchini, + "Cucumber": :cucumber, + "Melon": :melon, + "Sweet Corn": :sweet_corn, + "Bean": :bean, + "Parsnip": :parsnip, + "Carrot": :carrot, + "Beetroot": :beetroot + ], + prompt: "Choose a value" %> <%= error_tag f, :plant %> <%= label f, :amount %> diff --git a/lib/osuuspuutarha_web/live/yield_live/index.html.heex b/lib/osuuspuutarha_web/live/yield_live/index.html.heex index 67d0a91..33b73d0 100644 --- a/lib/osuuspuutarha_web/live/yield_live/index.html.heex +++ b/lib/osuuspuutarha_web/live/yield_live/index.html.heex @@ -28,7 +28,7 @@ <%= for yield <- @yields do %> <%= yield.date.day %>.<%= yield.date.month %>.<%= yield.date.year %> - <%= yield.plant %> + <%= Osuuspuutarha.Harvest.Parser.parse_plant(yield.plant) %> <%= yield.amount %> <%= yield.unit %> diff --git a/lib/osuuspuutarha_web/live/yield_live/show.html.heex b/lib/osuuspuutarha_web/live/yield_live/show.html.heex index 46d4a12..29ed75e 100644 --- a/lib/osuuspuutarha_web/live/yield_live/show.html.heex +++ b/lib/osuuspuutarha_web/live/yield_live/show.html.heex @@ -22,7 +22,7 @@
  • Plant: - <%= @yield.plant %> + <%= Osuuspuutarha.Harvest.Parser.parse_plant(@yield.plant) %>
  • diff --git a/test/osuuspuutarha/harvest_test.exs b/test/osuuspuutarha/harvest_test.exs index 8cfd103..dd1370a 100644 --- a/test/osuuspuutarha/harvest_test.exs +++ b/test/osuuspuutarha/harvest_test.exs @@ -21,12 +21,12 @@ defmodule Osuuspuutarha.HarvestTest do end test "create_yield/1 with valid data creates a yield" do - valid_attrs = %{amount: "120.5", date: ~D[2023-06-07], plant: :salad, unit: :kg} + valid_attrs = %{amount: "120.5", date: ~D[2023-06-07], plant: :lettuce, unit: :kg} assert {:ok, %Yield{} = yield} = Harvest.create_yield(valid_attrs) assert yield.amount == Decimal.new("120.5") assert yield.date == ~D[2023-06-07] - assert yield.plant == :salad + assert yield.plant == :lettuce assert yield.unit == :kg end diff --git a/test/osuuspuutarha_web/live/yield_live_test.exs b/test/osuuspuutarha_web/live/yield_live_test.exs index 3957fee..a24a0b8 100644 --- a/test/osuuspuutarha_web/live/yield_live_test.exs +++ b/test/osuuspuutarha_web/live/yield_live_test.exs @@ -4,8 +4,18 @@ defmodule OsuuspuutarhaWeb.YieldLiveTest do import Phoenix.LiveViewTest import Osuuspuutarha.HarvestFixtures - @create_attrs %{amount: "120.5", date: %{day: 7, month: 6, year: 2023}, plant: :salad, unit: :kg} - @update_attrs %{amount: "456.7", date: %{day: 8, month: 6, year: 2023}, plant: :carrot, unit: :kpl} + @create_attrs %{ + amount: "120.5", + date: %{day: 7, month: 6, year: 2023}, + plant: :lettuce, + unit: :kg + } + @update_attrs %{ + amount: "456.7", + date: %{day: 8, month: 6, year: 2023}, + plant: :carrot, + unit: :kpl + } @invalid_attrs %{amount: nil, date: %{day: 30, month: 2, year: 2023}, plant: nil, unit: nil} defp create_yield(_) do diff --git a/test/support/fixtures/harvest_fixtures.ex b/test/support/fixtures/harvest_fixtures.ex index b91a0a8..c29b45d 100644 --- a/test/support/fixtures/harvest_fixtures.ex +++ b/test/support/fixtures/harvest_fixtures.ex @@ -13,7 +13,7 @@ defmodule Osuuspuutarha.HarvestFixtures do |> Enum.into(%{ amount: "120.5", date: ~D[2023-06-07], - plant: :salad, + plant: :lettuce, unit: :kg }) |> Osuuspuutarha.Harvest.create_yield()