Player library, unified renderer for artists and playlists
This commit is contained in:
@@ -2,4 +2,12 @@ class Playlist < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :artist
|
||||
has_many :playlist_items, dependent: :destroy
|
||||
|
||||
def serialize
|
||||
data = {name: name, pic_url: pic_url, tracks: []}
|
||||
playlist_items.each do |item|
|
||||
data[:tracks] << item.track.serialize
|
||||
end
|
||||
data
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,4 +9,13 @@ class Album < ActiveRecord::Base
|
||||
def self.with_format f
|
||||
joins(:release_formats).where(:release_formats => { :hash => f.to_s })
|
||||
end
|
||||
|
||||
def serialize
|
||||
{
|
||||
name: name,
|
||||
pic_url: pic_url,
|
||||
year: year,
|
||||
tracks: tracks.map(&:serialize)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,6 +19,15 @@ class Artist < ActiveRecord::Base
|
||||
save!
|
||||
Delayed::Job.enqueue(LoadArtistJob.new(name))
|
||||
end
|
||||
|
||||
def serialize
|
||||
{
|
||||
name: name,
|
||||
pic_url: pic_url,
|
||||
desc: desc,
|
||||
albums: albums.map(&:serialize)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
@@ -14,4 +14,18 @@ class Track < ActiveRecord::Base
|
||||
'0:00'
|
||||
end
|
||||
end
|
||||
|
||||
def serialize
|
||||
{
|
||||
id: id,
|
||||
artist: artists.first.name,
|
||||
album: album.name,
|
||||
position: position.to_s(36),
|
||||
name: name,
|
||||
length: length,
|
||||
duration: duration,
|
||||
available: available,
|
||||
album_pic: album.pic_url
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user