defmodule NullaWeb.Api.RelationController do use NullaWeb, :controller alias Nulla.Relations alias Nulla.Relations.Relation action_fallback NullaWeb.FallbackController def index(conn, _params) do relations = Relations.list_relations() render(conn, :index, relations: relations) end def create(conn, %{"relation" => relation_params}) do with {:ok, %Relation{} = relation} <- Relations.create_relation(relation_params) do conn |> put_status(:created) |> put_resp_header("location", ~p"/api/relations/#{relation}") |> render(:show, relation: relation) end end def show(conn, %{"id" => id}) do relation = Relations.get_relation!(id) render(conn, :show, relation: relation) end def update(conn, %{"id" => id, "relation" => relation_params}) do relation = Relations.get_relation!(id) with {:ok, %Relation{} = relation} <- Relations.update_relation(relation, relation_params) do render(conn, :show, relation: relation) end end def delete(conn, %{"id" => id}) do relation = Relations.get_relation!(id) with {:ok, %Relation{}} <- Relations.delete_relation(relation) do send_resp(conn, :no_content, "") end end end