diff --git a/web/app/controllers/api_search_controller.rb b/web/app/controllers/api_search_controller.rb index bb5ae90cd..bc150aab4 100644 --- a/web/app/controllers/api_search_controller.rb +++ b/web/app/controllers/api_search_controller.rb @@ -156,7 +156,7 @@ class ApiSearchController < ApiController sobj = MusicianSearch.user_search_filter(current_user) @search = sobj.search_results_page(filter_params, page, user_ids) - respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/index' + respond_with @search, responder: ApiResponder, status: 201, template: 'api_search/filter' rescue => exception logger.debug("Latency exception: #{exception.message}") diff --git a/web/app/views/api_search/filter.rabl b/web/app/views/api_search/filter.rabl new file mode 100644 index 000000000..cf1909426 --- /dev/null +++ b/web/app/views/api_search/filter.rabl @@ -0,0 +1,81 @@ +object @search + +node :page_count do |foo| + @search.page_count +end + +node :my_audio_latency do |user| + current_user.last_jam_audio_latency.round if current_user.last_jam_audio_latency +end + +node :filter_json do |foo| + @search.to_json +end + +# node :description do |foo| +# @search.description +# end + +node :is_blank_filter do |foo| + @search.is_blank? +end + +child(:results => :musicians) { + attributes :id, :first_name, :last_name, :name, :city, :state, :country, :online, :musician, :photo_url, :biography, :regionname, :score, :full_score + + node :is_friend do |musician| + @search.is_friend?(musician) + end + + node :is_following do |musician| + @search.is_follower?(musician) + end + + node :pending_friend_request do |musician| + musician.pending_friend_request?(current_user) + end + + node :biography do |musician| + musician.biography.nil? ? "" : musician.biography + end + + child :musician_instruments => :instruments do + attributes :instrument_id, :description, :proficiency_level, :priority + end + + child :top_followings => :followings do |uf| + node :user_id do |uu| uu.id end + node :photo_url do |uu| uu.photo_url end + node :name do |uu| uu.name end + end + + node :friend_count do |musician| @search.friend_count(musician) end + node :follow_count do |musician| @search.follow_count(musician) end + node :recording_count do |musician| @search.record_count(musician) end + node :session_count do |musician| @search.session_count(musician) end + + node :audio_latency do |musician| + last_jam_audio_latency(musician) + end + + node :latency_data do |musician| + + if latency = @latency_data.detect{|l_data| l_data[:user_id] == musician.id } + { + audio_latency: latency[:audio_latency], + ars_internet_latency: latency[:ars_internet_latency], + ars_total_latency: latency[:ars_total_latency] + } + end if @latency_data + end + + node :last_active_timestamp do |musician| + if musician.updated_at || musician.last_jam_updated_at + [musician.updated_at, musician.last_jam_updated_at].compact.max.to_i + end + end + + child :genres => :genres do + attributes :genre_id, :description + end +} \ No newline at end of file diff --git a/web/app/views/api_search/index.rabl b/web/app/views/api_search/index.rabl index 7a496f0de..aec758cb3 100644 --- a/web/app/views/api_search/index.rabl +++ b/web/app/views/api_search/index.rabl @@ -15,9 +15,9 @@ if @search.is_a?(BaseSearch) end if @search.is_a? MusicianSearch - node :description do |foo| - @search.description - end + # node :description do |foo| + # @search.description + # end node :is_blank_filter do |foo| @search.is_blank? diff --git a/web/spec/controllers/api_search_controller_spec.rb b/web/spec/controllers/api_search_controller_spec.rb index 7eecffa2c..8808868e4 100644 --- a/web/spec/controllers/api_search_controller_spec.rb +++ b/web/spec/controllers/api_search_controller_spec.rb @@ -23,7 +23,7 @@ describe ApiSearchController, type: :controller do response.should be_success expect(response.content_type).to eq("application/json") - expect(response).to render_template(:index) + expect(response).to render_template(:filter) expect(response).to have_http_status(:created) end end diff --git a/web/spec/requests/musician_filter_api_spec.rb b/web/spec/requests/musician_filter_api_spec.rb index 875daf232..865005ee9 100644 --- a/web/spec/requests/musician_filter_api_spec.rb +++ b/web/spec/requests/musician_filter_api_spec.rb @@ -161,7 +161,7 @@ describe "Musician Filter API", type: :request do it "filter GOOD latency users" do post '/api/filter.json', { latency_good: true, latency_fair: false, latency_high: false } expect(response.content_type).to eq("application/json") - expect(response).to render_template(:index) + expect(response).to render_template(:filter) expect(response).to have_http_status(:created) expect(JSON.parse(response.body)["musicians"].size).to eq(2)