some comments + total airtimes for tracks/artist/releases
This commit is contained in:
parent
9df604a203
commit
727e06851d
@ -9,6 +9,7 @@ local models = autoload("models")
|
|||||||
local function Artisthandler(self)
|
local function Artisthandler(self)
|
||||||
local artist_id = self.params.artist
|
local artist_id = self.params.artist
|
||||||
|
|
||||||
|
-- find the artist
|
||||||
local artist = models.Artists:find({ id = artist_id })
|
local artist = models.Artists:find({ id = artist_id })
|
||||||
if not artist then
|
if not artist then
|
||||||
self:write({"Not Found", status = 404})
|
self:write({"Not Found", status = 404})
|
||||||
@ -25,6 +26,7 @@ local function Artisthandler(self)
|
|||||||
artist[field] = nil
|
artist[field] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- find all tracks with this artist
|
||||||
local tracks = db.query([[
|
local tracks = db.query([[
|
||||||
SELECT track.name AS track_name, track.id
|
SELECT track.name AS track_name, track.id
|
||||||
FROM track_artists
|
FROM track_artists
|
||||||
@ -35,7 +37,12 @@ local function Artisthandler(self)
|
|||||||
|
|
||||||
artist["tracks"] = tracks
|
artist["tracks"] = tracks
|
||||||
|
|
||||||
|
|
||||||
|
-- find all airtimes for each track
|
||||||
|
local total_airtimes = 0
|
||||||
|
|
||||||
for i, track in ipairs(tracks) do
|
for i, track in ipairs(tracks) do
|
||||||
|
local track_airtimes = 0
|
||||||
local airtimes = db.query([[
|
local airtimes = db.query([[
|
||||||
SELECT airtime, station AS station_id
|
SELECT airtime, station AS station_id
|
||||||
FROM airtimes
|
FROM airtimes
|
||||||
@ -45,8 +52,12 @@ local function Artisthandler(self)
|
|||||||
artist["tracks"][i]["airtimes"] = {}
|
artist["tracks"][i]["airtimes"] = {}
|
||||||
for j, airtime in ipairs(airtimes) do
|
for j, airtime in ipairs(airtimes) do
|
||||||
table.insert(artist["tracks"][i]["airtimes"], airtime)
|
table.insert(artist["tracks"][i]["airtimes"], airtime)
|
||||||
|
track_airtimes = track_airtimes + 1
|
||||||
|
total_airtimes = total_airtimes + 1
|
||||||
end
|
end
|
||||||
|
artist["tracks"][i]["track_airtimes"] = track_airtimes
|
||||||
|
|
||||||
|
-- find all releases with this track
|
||||||
local releases = db.query([[
|
local releases = db.query([[
|
||||||
SELECT release.id AS release_id, release.name AS release_name
|
SELECT release.id AS release_id, release.name AS release_name
|
||||||
FROM track_releases
|
FROM track_releases
|
||||||
@ -62,6 +73,7 @@ local function Artisthandler(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
artist["total_airtimes"] = total_airtimes
|
||||||
|
|
||||||
return { json = artist }
|
return { json = artist }
|
||||||
|
|
||||||
|
|||||||
@ -25,6 +25,7 @@ local function Releasehandler(self)
|
|||||||
release[field] = nil
|
release[field] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get all tracks on this release
|
||||||
local tracks = db.query([[
|
local tracks = db.query([[
|
||||||
SELECT track.name AS track_name, track.id, artist.name AS artist_name
|
SELECT track.name AS track_name, track.id, artist.name AS artist_name
|
||||||
FROM track_releases
|
FROM track_releases
|
||||||
@ -39,7 +40,11 @@ local function Releasehandler(self)
|
|||||||
|
|
||||||
release["tracks"] = tracks
|
release["tracks"] = tracks
|
||||||
|
|
||||||
|
-- find all airtimes for each track
|
||||||
|
local total_airtimes = 0
|
||||||
|
|
||||||
for i, track in ipairs(tracks) do
|
for i, track in ipairs(tracks) do
|
||||||
|
local track_airtimes = 0
|
||||||
local airtimes = db.query([[
|
local airtimes = db.query([[
|
||||||
SELECT airtime, station AS station_id
|
SELECT airtime, station AS station_id
|
||||||
FROM airtimes
|
FROM airtimes
|
||||||
@ -49,8 +54,12 @@ local function Releasehandler(self)
|
|||||||
release["tracks"][i]["airtimes"] = {}
|
release["tracks"][i]["airtimes"] = {}
|
||||||
for j, airtime in ipairs(airtimes) do
|
for j, airtime in ipairs(airtimes) do
|
||||||
table.insert(release["tracks"][i]["airtimes"], airtime)
|
table.insert(release["tracks"][i]["airtimes"], airtime)
|
||||||
|
track_airtimes = track_airtimes + 1
|
||||||
|
total_airtimes = total_airtimes + 1
|
||||||
end
|
end
|
||||||
|
release["tracks"][i]["track_airtimes"] = track_airtimes
|
||||||
end
|
end
|
||||||
|
release["total_airtimes"] = total_airtimes
|
||||||
|
|
||||||
return { json = release }
|
return { json = release }
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,6 @@ local function Stationhandler(self)
|
|||||||
return { json = self.airtimes }
|
return { json = self.airtimes }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
self.station_id = station_id
|
self.station_id = station_id
|
||||||
self.offset = tonumber(offset)
|
self.offset = tonumber(offset)
|
||||||
self.limit = tonumber(limit)
|
self.limit = tonumber(limit)
|
||||||
|
|||||||
@ -25,6 +25,7 @@ local function Trackhandler(self)
|
|||||||
track[field] = nil
|
track[field] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- find the artist for this track
|
||||||
local artists = db.query([[
|
local artists = db.query([[
|
||||||
SELECT artist.name AS artist_name
|
SELECT artist.name AS artist_name
|
||||||
FROM track_artists
|
FROM track_artists
|
||||||
@ -33,9 +34,10 @@ local function Trackhandler(self)
|
|||||||
WHERE track_artists.track = ?
|
WHERE track_artists.track = ?
|
||||||
]], track["id"])
|
]], track["id"])
|
||||||
|
|
||||||
|
|
||||||
track["artist"] = artists[1]["artist_name"]
|
track["artist"] = artists[1]["artist_name"]
|
||||||
|
|
||||||
|
-- find all airtimes for this track
|
||||||
|
local track_airtimes = 0
|
||||||
local airtimes = db.query([[
|
local airtimes = db.query([[
|
||||||
SELECT airtime, station AS station_id
|
SELECT airtime, station AS station_id
|
||||||
FROM airtimes
|
FROM airtimes
|
||||||
@ -45,8 +47,11 @@ local function Trackhandler(self)
|
|||||||
track["airtimes"] = {}
|
track["airtimes"] = {}
|
||||||
for i, airtime in ipairs(airtimes) do
|
for i, airtime in ipairs(airtimes) do
|
||||||
track["airtimes"][i] = airtime
|
track["airtimes"][i] = airtime
|
||||||
|
track_airtimes = track_airtimes + 1
|
||||||
end
|
end
|
||||||
|
track["total_airtimes"] = track_airtimes
|
||||||
|
|
||||||
|
-- find all releases for this track
|
||||||
local releases = db.query([[
|
local releases = db.query([[
|
||||||
SELECT release.id AS release_id, release.name AS release_name
|
SELECT release.id AS release_id, release.name AS release_name
|
||||||
FROM track_releases
|
FROM track_releases
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user