mythicalprogrammer / fumigate

0 stars 0 forks source link

perfume_approval :delete + submit (moving perfume approved to regular perfume) #255

Closed mythicalprogrammer closed 4 years ago

mythicalprogrammer commented 4 years ago
mythicalprogrammer commented 4 years ago

<%= link "Approve", to: Routes.admin_perfume_approval_path(@conn, :new), class: "btn btn-outline-secondary" %>

Button needs to pass current perfume down to the controller.

mythicalprogrammer commented 4 years ago

Fuck it we're doing custom action.

https://hexdocs.pm/phoenix/controllers.html#actions

Need to code route and code controller

mythicalprogrammer commented 4 years ago

controller:

   105   def approve(conn, params) do
   106     require Logger
   107     Logger.info("Hello from approve action. Inspectin params content: #{inspect(params)}")
   108   end

router:

65   scope "/admin", FumigateWeb.Admin, as: :admin do
66     pipe_through [:browser, :protected, :admin_only]
...
  73     resources "/perfumes_approval", PerfumeApprovalController
  74     post "/perfumes_approval", PerfumeApprovalController, :approve
  75
  76   end

template:

 53         <%= link "Approve", to: Routes.admin_perfume_approval_path(@conn, :approve, perfume), class: "btn btn-     outline-secondary" %>

After adding the above code, defining a custom action for controller and wired up the router for that custom action, ya gonna to get this error:

Protocol.UndefinedError at GET /admin/perfumes_approval protocol Enumerable not implemented for %Fumigate.Approval.PerfumeApproval{meta: #Ecto.Schema.Metadata<:loaded, "perfume_approvals">, accords: [%Fumigate.Fragrance.Accord{meta: #Ecto.Schema.Metadata<:loaded, "accords">, accord_name: "almond", id: 35, inserted_at: ~N[2019-07-20 19:14:48], perfume_approvals: #Ecto.Association.NotLoaded, perfumes: #Ecto.Association.NotLoaded, updated_at: ~N[2019-07-20 19:14:48]}, %Fumigate.Fragrance.Accord{meta: #Ecto.Schema.Metadata<:loaded, "accords">, accord_name: "animalic", id: 32, inserted_at: ~N[2019-07-20 19:14:48], perfume_approvals: #Ecto.Association.NotLoaded, perfumes: #Ecto.Association.NotLoaded, updated_at: ~N[2019-07-20 19:14:48]}, %Fumigate.Fragrance.Accord{meta: #Ecto.Schema.Metadata<:loaded, "accords">, accord_name: "aromatic", id: 9, inserted_at: ~N[2019-07-20 19:14:48], perfume_approvals: #Ecto.Association.NotLoaded, perfumes: #Ecto.Association.NotLoaded, updated_at: ~N[2019-07-20 19:14:48]}], companies: [], concentration: "hawt", day_released: 3, gender: :men, id: 1, inserted_at: ~N[2019-07-22 07:17:25], month_released: :may, notes: [%Fumigate.Fragrance.Note{meta: #Ecto.Schema.Metadata<:loaded, "notes">, id: 236, inserted_at: ~N[2019-07-20 19:15:38], note_name: "African Orange flower", perfumes: #Ecto.Association.NotLoaded, updated_at: ~N[2019-07-20 19:15:38]}, %Fumigate.Fragrance.Note{meta: #Ecto.Schema.Metadata<:loaded, "notes">, id: 160, inserted_at: ~N[2019-07-20 19:15:38], note_name: "Almond Blossom", perfumes: #Ecto.Association.NotLoaded, updated_at: ~N[2019-07-20 19:15:38]}, %Fumigate.Fragrance.Note{meta: #Ecto.Schema.Metadata<:loaded, "notes">, id: 237, inserted_at: ~N[2019-07-20 19:15:38], note_name: "Amalfi Lemon", perfumes: #Ecto.Association.NotLoaded, updated_at: ~N[2019-07-20 19:15:38]}], perfume_description: "testing perfume approval", perfume_name: "Bot rob", picture_url: "adf", updated_at: ~N[2019-07-24 01:01:23], year_released: 2019}. This protocol is implemented for: Ecto.Adapters.SQL.Stream, Postgrex.Stream, DBConnection.Stream, DBConnection.PrepareStream, Scrivener.Page, HashSet, Range, Map, Function, List, Stream, Date.Range, HashDict, GenEvent.Stream, MapSet, File.Stream, IO.Stream

mythicalprogrammer commented 4 years ago

This error can be hella cryptic.

It just basically state that the inspect function in the debug line does not know how to print out params.

But what cool is it print out the structure of params so it lets me know what to extract out of it and what I need.

mythicalprogrammer commented 4 years ago

fuck

Compiling 2 files (.ex)
warning: this clause cannot match because a previous clause at line 73 always matches
  lib/fumigate_web/router.ex:2

Offending code:

router:

  65   scope "/admin", FumigateWeb.Admin, as: :admin do
  66     pipe_through [:browser, :protected, :admin_only]
...
  73     post "/perfumes_approval", PerfumeApprovalController, :approve
  74     resources "/perfumes_approval", PerfumeApprovalController
  75
  76   end
mythicalprogrammer commented 4 years ago

route I am using so far for perfume approval controller:

mythicalprogrammer commented 4 years ago

https://elixirforum.com/t/is-there-a-good-way-to-dump-params-from-a-controller-action/24213/5

Decided to use the action new and pass perfume_approval's id instead of the whole ecto record.

the new action in controller will have to relook up the record by id to do logic. It's bad because I have to hit the database but it should technically works.

mythicalprogrammer commented 4 years ago

test

Check approve works

Then check if dupe against approval works

then check delete works after approving

mythicalprogrammer commented 4 years ago

Adding perfume approval to perfume table works.

DUPE check does not work. Because: the join table are not added.

join tables that need to be added when insert perfume table:

done.

Dupe warning does not work. Dupe works just not the warning. - works now

Dupe doesn't work if companies aren't added. Make sure that user add companies.

mythicalprogrammer commented 4 years ago

work on delete first before checking companies is added or not

mythicalprogrammer commented 4 years ago

delete works now.

Going to do check if companies are added or not before can be approve