20cd1bb579
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
43 lines
1.1 KiB
Elixir
43 lines
1.1 KiB
Elixir
defmodule EventosWeb.EventController do
|
|
use EventosWeb, :controller
|
|
|
|
alias Eventos.Events
|
|
alias Eventos.Events.Event
|
|
|
|
action_fallback EventosWeb.FallbackController
|
|
|
|
def index(conn, _params) do
|
|
events = Events.list_events()
|
|
render(conn, "index.json", events: events)
|
|
end
|
|
|
|
def create(conn, %{"event" => event_params}) do
|
|
with {:ok, %Event{} = event} <- Events.create_event(event_params) do
|
|
conn
|
|
|> put_status(:created)
|
|
|> put_resp_header("location", event_path(conn, :show, event))
|
|
|> render("show.json", event: event)
|
|
end
|
|
end
|
|
|
|
def show(conn, %{"id" => id}) do
|
|
event = Events.get_event!(id)
|
|
render(conn, "show.json", event: event)
|
|
end
|
|
|
|
def update(conn, %{"id" => id, "event" => event_params}) do
|
|
event = Events.get_event!(id)
|
|
|
|
with {:ok, %Event{} = event} <- Events.update_event(event, event_params) do
|
|
render(conn, "show.json", event: event)
|
|
end
|
|
end
|
|
|
|
def delete(conn, %{"id" => id}) do
|
|
event = Events.get_event!(id)
|
|
with {:ok, %Event{}} <- Events.delete_event(event) do
|
|
send_resp(conn, :no_content, "")
|
|
end
|
|
end
|
|
end
|