restrict ammo groups by user_id
This commit is contained in:
		| @@ -5,7 +5,7 @@ defmodule CanneryWeb.AmmoTypeLive.Show do | ||||
|  | ||||
|   use CanneryWeb, :live_view | ||||
|   import CanneryWeb.AmmoGroupLive.AmmoGroupCard | ||||
|   alias Cannery.{Ammo, Repo} | ||||
|   alias Cannery.{Ammo} | ||||
|  | ||||
|   @impl true | ||||
|   def mount(_params, session, socket) do | ||||
| @@ -13,14 +13,16 @@ defmodule CanneryWeb.AmmoTypeLive.Show do | ||||
|   end | ||||
|  | ||||
|   @impl true | ||||
|   def handle_params(%{"id" => id}, _, socket) do | ||||
|     ammo_type = Ammo.get_ammo_type!(id) |> Repo.preload(:ammo_groups) | ||||
|   def handle_params(%{"id" => id}, _, %{assigns: %{current_user: current_user}} = socket) do | ||||
|     ammo_type = Ammo.get_ammo_type!(id) | ||||
|     ammo_groups = ammo_type |> Ammo.list_ammo_groups_for_type(current_user) | ||||
|  | ||||
|     socket = | ||||
|       socket | ||||
|       |> assign( | ||||
|         page_title: page_title(socket.assigns.live_action), | ||||
|         ammo_type: ammo_type, | ||||
|         ammo_groups: ammo_groups, | ||||
|         avg_cost_per_round: ammo_type |> Ammo.get_average_cost_for_ammo_type!() | ||||
|       ) | ||||
|  | ||||
|   | ||||
| @@ -92,10 +92,10 @@ | ||||
|   <hr class="hr"> | ||||
|  | ||||
|   <div> | ||||
|     <%= if @ammo_type.ammo_groups |> Enum.empty?() do %> | ||||
|     <%= if @ammo_groups |> Enum.empty?() do %> | ||||
|       No ammo for this type | ||||
|     <% else %> | ||||
|       <%= for ammo_group <- @ammo_type.ammo_groups do %> | ||||
|       <%= for ammo_group <- @ammo_groups do %> | ||||
|         <.ammo_group_card ammo_group={ammo_group} /> | ||||
|       <% end %> | ||||
|     <% end %> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user