Render artist page with serialized data, artist playlist by name

This commit is contained in:
magnolia-fan
2011-11-27 17:01:46 +04:00
parent 9ec28708c5
commit 9032e8380b
7 changed files with 47 additions and 42 deletions
@@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
def compile_page params
@data = params[:data] unless params[:data].nil?
@status = params[:status] unless params[:status].nil?
render json: {
renderer: "unified",
data: @data,
@@ -21,6 +22,10 @@ class ApplicationController < ActionController::Base
}, include: (params[:include] unless params[:include].nil?)
end
def get_artist_name_from_query
params[:artist].gsub('%20', ' ').gsub('+', ' ').gsub('.html', '')
end
protected
def authorize
+4 -8
View File
@@ -1,19 +1,19 @@
class ArtistController < ApplicationController
def data
# Bad params
if params[:name].nil? or params[:name].empty?
return render json: { status: 'loading_failed' }
if params[:artist].nil? or params[:artist].empty?
return render json: { status: 'loading_failed' }, status: 404
end
# Searching for artist
artist_name = get_artist_name_from_query
@artist = Artist.find_by_name(artist_name, include: { artist_links: {}, albums: { tracks: {}}})
@artist = Artist.find_by_name(artist_name)
# Artist not found in DB
unless @artist
results = MusicBrainz::Artist.search(artist_name)
if results.empty?
return render json: { status: 'not_found' }
return render json: { status: 'not_found' }, status: 404
end
best_match = results[0][:sort_name]
if best_match != artist_name and similar_names(artist_name, best_match)
@@ -43,10 +43,6 @@ class ArtistController < ApplicationController
end
private
def get_artist_name_from_query
params[:name].gsub('%20', ' ').gsub('+', ' ').gsub('.html', '')
end
def queue_loading artist_name, mbid
@artist = Artist.create( name: artist_name, mbid: mbid, status: 0 )
+1 -1
View File
@@ -5,7 +5,7 @@ class PlaylistController < ApplicationController
end
def lastfm_top50
artist = Artist.find_by_id(params[:id])
artist = Artist.find_by_name(get_artist_name_from_query)
return if artist.nil?
playlist = Playlist.new(name: "#{artist.name}: Last.fm TOP 50", artist: artist, pic_url: artist.pic_url)