Import w/ desc and pics
This commit is contained in:
@@ -1,2 +1,25 @@
|
||||
class ArtistController < ApplicationController
|
||||
def data
|
||||
data = {}
|
||||
artist = Artist.find_by_name(params[:name])
|
||||
data['artist'] = {name: artist.name, desc: artist.desc, pic: artist.pic_url}
|
||||
data['albums'] = []
|
||||
albums = artist.albums
|
||||
albums.each do |album|
|
||||
tmp_album = {name: album.name, year: album.year, pic: album.pic_url}
|
||||
album_tracks = []
|
||||
bonus_tracks = []
|
||||
album.tracks.each do |track|
|
||||
tmp_track = {name: track.name, live: track.live, acoustic: track.acoustic}
|
||||
time = (track.length / 1000).round
|
||||
time_m = (time / 60).floor
|
||||
time_s = time - time_m * 60
|
||||
tmp_track['duration'] = time_m.to_s + ':' + (time_s < 10 ? '0' : '') + time_s.to_s
|
||||
(track.bonus == 0 ? album_tracks : bonus_tracks) << tmp_track
|
||||
end
|
||||
tmp_album['tracks'] = {album: album_tracks, bonus: bonus_tracks}
|
||||
data['albums'] << tmp_album
|
||||
end
|
||||
render :json => data
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
class Album < ActiveRecord::Base
|
||||
belongs_to :artist
|
||||
has_many :tracks, :order => 'bonus ASC, position ASC'
|
||||
end
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
class Artist < ActiveRecord::Base
|
||||
has_many :albums, :conditions => "status = 1", :order => 'year ASC, id ASC'
|
||||
end
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
class Track < ActiveRecord::Base
|
||||
belongs_to :album
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user