Delete function in todo list

Hi, I am new to Elixir/Phoenix. This combination seems like an amazing tool though!

I am following: https://dennisbeatty.com/how-to-create-a-todo-list-with-phoenix-liveview.html
to create a simple todo list. Everything works as intended. I want to add a delete button to the list.

Here is what I have done:

<button phx-click="delete" phx-value-id="<%= todo.id %>">Delete</button>

_________________________________________________________________________

def handle_event("delete", %{"id" => id}, socket) do
  todo = Todos.get_todo!(id)
  Todos.delete_todo(id)
  {:noreply, socket}
end

I am getting an error when clicking the button: (FunctionClauseError) no function clause matching in LiveViewTodos.Todos.delete_todo/1

Also, there is a built-in function to handle the delete_todo in my todos.ex:

  @doc """
  Deletes a todo.

  ## Examples

      iex> delete_todo(todo)
      {:ok, %Todo{}}

      iex> delete_todo(todo)
      {:error, %Ecto.Changeset{}}

  """
  def delete_todo(%Todo{} = todo) do
    todo
    |> Repo.delete()
    |> broadcast_change([:todo, :deleted])
  end

Can’t seem to figure out what’s going on here. Any help is much appreciated!

Todos.delete_todo(id)

delete_todo(%Todo{} = todo)

There is a type mismatch between the item your function is expecting and one that you are providing it. %Todo{} is a map/struct type and id would probably be some kind of binary/string type.

You could fix it by either retrieving the %Todo{} that might exist in the LiveView or update the db function to delete using the id.