VRFS-2822 : Add options to query for both filtering on artist and grouping on artist (to get a list of artists through existing query infrastructure).
This commit is contained in:
parent
c8059e9c00
commit
e91ee68d58
|
|
@ -57,6 +57,18 @@ module JamRuby
|
|||
accepts_nested_attributes_for :jam_track_tap_ins, allow_destroy: true
|
||||
|
||||
class << self
|
||||
# @return array[artist_name(string)]
|
||||
def all_artists
|
||||
JamTrack.select("original_artist").
|
||||
group("original_artist").
|
||||
collect{|jam_track|jam_track.original_artist}
|
||||
end
|
||||
|
||||
# @return array[JamTrack] for given artist_name
|
||||
def tracks_for_artist(artist_name)
|
||||
JamTrack.where("original_artist=?", artist_name).all
|
||||
end
|
||||
|
||||
def index(options, user)
|
||||
limit = options[:limit]
|
||||
limit ||= 20
|
||||
|
|
@ -72,6 +84,14 @@ module JamRuby
|
|||
query = query.joins(:jam_track_rights)
|
||||
query = query.where("jam_track_rights.user_id = ?", user.id)
|
||||
end
|
||||
|
||||
if options[:artist_name]
|
||||
query = query.where("original_artist=?", options[:artist_name])
|
||||
end
|
||||
|
||||
if options[:group_artist]
|
||||
query = query.group("original_artist")
|
||||
end
|
||||
|
||||
query = query.where("jam_tracks.available = ?", true) unless user.admin
|
||||
query = query.where("jam_tracks.genre_id = '#{options[:genre]}'") unless options[:genre].blank?
|
||||
|
|
|
|||
Loading…
Reference in New Issue