Update
This commit is contained in:
parent
188bc08494
commit
4af88f3e1d
44 changed files with 1041 additions and 34 deletions
43
lib/nulla_web/controllers/api/relation_controller.ex
Normal file
43
lib/nulla_web/controllers/api/relation_controller.ex
Normal file
|
@ -0,0 +1,43 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue