JSON views: albums, events (#22)
* Provide location in Directus client event payload * Add Feed controller with views: album.json * Enable Feedcontroller :albums view * Add event json to Feed Controller * Enable Feed Controller event json view
This commit is contained in:
parent
3725dc17d0
commit
7e2010efb0
3 changed files with 83 additions and 1 deletions
|
|
@ -99,7 +99,8 @@ defmodule Mse25.Directus do
|
|||
"started_at",
|
||||
"ended_at",
|
||||
"bands.artists_id.name",
|
||||
"mia.artists_id.name"
|
||||
"mia.artists_id.name",
|
||||
"location.*"
|
||||
],
|
||||
","
|
||||
)
|
||||
|
|
|
|||
79
lib/mse25_web/controllers/feed_controller.ex
Normal file
79
lib/mse25_web/controllers/feed_controller.ex
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
defmodule Mse25Web.FeedController do
|
||||
use Mse25Web, :controller
|
||||
alias Mse25.Directus
|
||||
alias Mse25.Timeline
|
||||
|
||||
def atom_feed() do
|
||||
:tbw
|
||||
end
|
||||
|
||||
def upcoming_events_ics() do
|
||||
:tbw
|
||||
end
|
||||
|
||||
def albums_json(conn, _) do
|
||||
json(
|
||||
conn,
|
||||
Directus.get_albums!()
|
||||
|> Enum.map(fn %{
|
||||
"album" => album,
|
||||
"artist" => artist,
|
||||
"externalId" => id,
|
||||
"year" => year,
|
||||
"purchased_at" => purchased_on,
|
||||
"contents" => contents,
|
||||
"songs" => songs
|
||||
} ->
|
||||
{img, ""} = Integer.parse(id)
|
||||
|
||||
%{
|
||||
id: id,
|
||||
img: to_string(img - 1) <> ".jpg",
|
||||
title: album,
|
||||
artist: artist,
|
||||
album: album,
|
||||
year: year,
|
||||
purchased_on: purchased_on,
|
||||
description: Earmark.as_html!(contents),
|
||||
songs: Enum.map(songs, fn %{"title" => song} -> song end)
|
||||
}
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
def events_json(conn, _) do
|
||||
json(
|
||||
conn,
|
||||
Directus.get_events!(limit: 9999)
|
||||
|> Enum.map(fn %{
|
||||
"title" => title,
|
||||
"lead" => lead,
|
||||
"poster" => img,
|
||||
"started_at" => date,
|
||||
"location" => %{
|
||||
"name" => venue,
|
||||
"address" => region,
|
||||
"position" => %{
|
||||
"coordinates" => [lat, lng]
|
||||
}
|
||||
},
|
||||
"bands" => bands
|
||||
} ->
|
||||
%{
|
||||
title: title,
|
||||
lead: lead,
|
||||
img: img,
|
||||
date: String.slice(date, 0..9),
|
||||
region: region,
|
||||
venue: venue,
|
||||
location: [lng, lat],
|
||||
bands: Enum.map(bands, fn %{"artists_id" => %{"name" => band}} -> band end)
|
||||
}
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
def event_map_js() do
|
||||
:tbw
|
||||
end
|
||||
end
|
||||
|
|
@ -26,6 +26,8 @@ defmodule Mse25Web.Router do
|
|||
# get "/kommande-evenemang.ics", EventController, :calendar
|
||||
# get "/event-map.js", EventController, :interactive_map
|
||||
# get "/prenumerera.xml", TimelineController, :feed
|
||||
get "/albums.json", FeedController, :albums_json
|
||||
get "/events.json", FeedController, :events_json
|
||||
|
||||
get "/*path", ItemController, :index
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue