link to release; airtimes on artist and release
This commit is contained in:
parent
e1ed8cda9a
commit
7d1efd0684
@ -29,4 +29,8 @@ app:match("artist", "/artist/:artist", json_params(function(self)
|
||||
return handlers.Artisthandler(self)
|
||||
end))
|
||||
|
||||
app:match("release", "/release/:release", json_params(function(self)
|
||||
return handlers.Releasehandler(self)
|
||||
end))
|
||||
|
||||
return app
|
||||
|
||||
@ -12,6 +12,7 @@ local function Artisthandler(self)
|
||||
local artist = models.Artists:find({ id = artist_id })
|
||||
if not artist then
|
||||
self:write({"Not Found", status = 404})
|
||||
return
|
||||
end
|
||||
|
||||
local hidden_fields = {
|
||||
@ -25,7 +26,7 @@ local function Artisthandler(self)
|
||||
end
|
||||
|
||||
local tracks = db.query([[
|
||||
SELECT track.name AS track_name, release.name AS release_name
|
||||
SELECT track.name AS track_name, track.id, release.name AS release_name
|
||||
FROM track_artists
|
||||
INNER JOIN
|
||||
tracks AS track ON (track_artists.track = track.id)
|
||||
@ -36,19 +37,20 @@ local function Artisthandler(self)
|
||||
WHERE track_artists.artist = ?
|
||||
]], artist["id"])
|
||||
|
||||
|
||||
artist["tracks"] = tracks
|
||||
|
||||
-- local airtimes = db.query([[
|
||||
-- SELECT airtime
|
||||
-- FROM airtimes
|
||||
-- WHERE track = ?
|
||||
-- ]], track["id"])
|
||||
for i, track in ipairs(tracks) do
|
||||
local airtimes = db.query([[
|
||||
SELECT airtime
|
||||
FROM airtimes
|
||||
WHERE track = ?
|
||||
]], track["id"])
|
||||
|
||||
-- artist["airtimes"] = {}
|
||||
-- for i, airtime in ipairs(airtimes) do
|
||||
-- artist["airtimes"][i] = airtime.airtime
|
||||
-- end
|
||||
artist["tracks"][i]["airtimes"] = {}
|
||||
for j, airtime in ipairs(airtimes) do
|
||||
table.insert(artist["tracks"][i]["airtimes"], airtime['airtime'])
|
||||
end
|
||||
end
|
||||
|
||||
return { json = artist }
|
||||
|
||||
|
||||
59
code/handlers/releasehandler.lua
Normal file
59
code/handlers/releasehandler.lua
Normal file
@ -0,0 +1,59 @@
|
||||
local db = require("lapis.db")
|
||||
local to_json = require("lapis.util").to_json
|
||||
local autoload = require("lapis.util").autoload
|
||||
local preload = require("lapis.db.model").preload
|
||||
|
||||
local models = autoload("models")
|
||||
|
||||
|
||||
local function Releasehandler(self)
|
||||
local release_id = self.params.release
|
||||
|
||||
local release = models.releases:find({ id = release_id })
|
||||
if not release then
|
||||
self:write({"Not Found", status = 404})
|
||||
return
|
||||
end
|
||||
|
||||
local hidden_fields = {
|
||||
"unique_name",
|
||||
"created_at",
|
||||
"updated_at"
|
||||
}
|
||||
|
||||
for i, field in ipairs(hidden_fields) do
|
||||
release[field] = nil
|
||||
end
|
||||
|
||||
local tracks = db.query([[
|
||||
SELECT track.name AS track_name, track.id, release.name AS release_name
|
||||
FROM track_releases
|
||||
INNER JOIN
|
||||
tracks AS track ON (track_releases.track = track.id)
|
||||
INNER JOIN
|
||||
track_releases AS track_release ON (track_release.track = track.id)
|
||||
INNER JOIN
|
||||
releases AS release ON (track_release.release = release.id)
|
||||
WHERE track_releases.release = ?
|
||||
]], release["id"])
|
||||
|
||||
release["tracks"] = tracks
|
||||
|
||||
for i, track in ipairs(tracks) do
|
||||
local airtimes = db.query([[
|
||||
SELECT airtime
|
||||
FROM airtimes
|
||||
WHERE track = ?
|
||||
]], track["id"])
|
||||
|
||||
release["tracks"][i]["airtimes"] = {}
|
||||
for j, airtime in ipairs(airtimes) do
|
||||
table.insert(release["tracks"][i]["airtimes"], airtime['airtime'])
|
||||
end
|
||||
end
|
||||
|
||||
return { json = release }
|
||||
|
||||
end
|
||||
|
||||
return Releasehandler
|
||||
@ -12,6 +12,7 @@ local function Trackhandler(self)
|
||||
local track = models.Tracks:find({ id = track_id })
|
||||
if not track then
|
||||
self:write({"Not Found", status = 404})
|
||||
return
|
||||
end
|
||||
|
||||
local hidden_fields = {
|
||||
|
||||
@ -20,7 +20,7 @@
|
||||
</h5>
|
||||
<p>
|
||||
<span style="padding-right:5px;color:#fff;">
|
||||
<% if item.release then %><%= item.release %><% end %>
|
||||
<% if item.release then %><a href="<%= url_for("release")..item.release_id %>" style="color: #ffffff; text-decoration: none;"><%= item.release %></a><% end %>
|
||||
<% if item.label then %>| <%= item.label %><% end %>
|
||||
<% if item.year then %>| <%= item.year %><% end %>
|
||||
<% if item.country then %>| <%= item.country %><% end %>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user