2018-10-11 17:37:39 +02:00
|
|
|
defmodule MobilizonWeb.TrackController do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Controller for Tracks
|
|
|
|
"""
|
2018-10-11 17:37:39 +02:00
|
|
|
use MobilizonWeb, :controller
|
2018-01-13 23:33:03 +01:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
alias Mobilizon.Events
|
|
|
|
alias Mobilizon.Events.Track
|
2018-01-13 23:33:03 +01:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
action_fallback(MobilizonWeb.FallbackController)
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
tracks = Events.list_tracks()
|
|
|
|
render(conn, "index.json", tracks: tracks)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create(conn, %{"track" => track_params}) do
|
|
|
|
with {:ok, %Track{} = track} <- Events.create_track(track_params) do
|
|
|
|
conn
|
|
|
|
|> put_status(:created)
|
|
|
|
|> put_resp_header("location", track_path(conn, :show, track))
|
|
|
|
|> render("show.json", track: track)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def show(conn, %{"id" => id}) do
|
|
|
|
track = Events.get_track!(id)
|
|
|
|
render(conn, "show.json", track: track)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update(conn, %{"id" => id, "track" => track_params}) do
|
|
|
|
track = Events.get_track!(id)
|
|
|
|
|
|
|
|
with {:ok, %Track{} = track} <- Events.update_track(track, track_params) do
|
|
|
|
render(conn, "show.json", track: track)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete(conn, %{"id" => id}) do
|
|
|
|
track = Events.get_track!(id)
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
with {:ok, %Track{}} <- Events.delete_track(track) do
|
|
|
|
send_resp(conn, :no_content, "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|