2017-12-09 14:58:37 +01:00
|
|
|
defmodule EventosWeb.SessionController do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Controller for (event) Sessions
|
|
|
|
"""
|
2017-12-09 14:58:37 +01:00
|
|
|
use EventosWeb, :controller
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
alias Eventos.Events
|
|
|
|
alias Eventos.Events.Session
|
|
|
|
|
2018-07-27 10:45:35 +02:00
|
|
|
action_fallback(EventosWeb.FallbackController)
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
sessions = Events.list_sessions()
|
|
|
|
render(conn, "index.json", sessions: sessions)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(conn, %{"session" => session_params}) do
|
|
|
|
with {:ok, %Session{} = session} <- Events.create_session(session_params) do
|
|
|
|
conn
|
|
|
|
|> put_status(:created)
|
|
|
|
|> put_resp_header("location", session_path(conn, :show, session))
|
|
|
|
|> render("show.json", session: session)
|
2017-12-09 14:58:37 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
def show(conn, %{"id" => id}) do
|
|
|
|
session = Events.get_session!(id)
|
|
|
|
render(conn, "show.json", session: session)
|
2017-12-09 14:58:37 +01:00
|
|
|
end
|
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
def show_sessions_for_event(conn, %{"uuid" => event_uuid}) do
|
|
|
|
sessions = Events.list_sessions_for_event(event_uuid)
|
2018-01-16 19:45:09 +01:00
|
|
|
render(conn, "index.json", sessions: sessions)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_sessions_for_track(conn, %{"id" => track}) do
|
|
|
|
sessions = Events.list_sessions_for_track(track)
|
|
|
|
render(conn, "index.json", sessions: sessions)
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
def update(conn, %{"id" => id, "session" => session_params}) do
|
|
|
|
session = Events.get_session!(id)
|
2017-12-09 14:58:37 +01:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
with {:ok, %Session{} = session} <- Events.update_session(session, session_params) do
|
|
|
|
render(conn, "show.json", session: session)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete(conn, %{"id" => id}) do
|
|
|
|
session = Events.get_session!(id)
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
with {:ok, %Session{}} <- Events.delete_session(session) do
|
|
|
|
send_resp(conn, :no_content, "")
|
|
|
|
end
|
2017-12-09 14:58:37 +01:00
|
|
|
end
|
2018-01-13 23:33:03 +01:00
|
|
|
end
|