more work

This commit is contained in:
Mike Slemmer 2013-05-13 22:09:29 -07:00
parent 127912b1fb
commit 20f809001a
8 changed files with 188 additions and 25 deletions

0
.rvmrc Normal file → Executable file
View File

View File

@ -1,28 +1,41 @@
class ApiClaimedRecordingsController < ApiController
before_filter :api_signed_in_user
before_filter :look_up_claimed_recording, :only => [ :show ]
before_filter :look_up_claimed_recording, :only => [ :show, :update, :delete ]
respond_to :json
# All recordings where the current user is a musician, whether owned by the user or not.
#
def index
@claimed_recordings = ClaimedRecording.find_by_user_id(current_user.id, :order => "created_at DESC").paginate(page: params[:page])
# FIXME: I suspect this will do a bunch of joins. Need to test it.
# NEED TO USE RABL here
respond_with @claimed_recordings, responder: ApiResponder, :status => 200
@claimed_recordings = ClaimedRecording.where(:user_id => current_user.id).order("created_at DESC").paginate(page: params[:page])
end
def show
@claimed_recording = ClaimedRecording.find(params[:id])
respond_with @claimed_recording, responder: ApiResponder, :status => 200
@claimed_recording
end
def update
begin
@claimed_recording.update_fields(current_user, params)
respond_with responder: ApiResponder, :status => 204
rescue
render :json => { :message => "claimed_recording could not be updated" }, :status => 403
end
end
def delete
begin
@claimed_recording.discard(current_user)
render :json => {}, :status => 204
# respond_with responder: ApiResponder, :status => 204
rescue
render :json => { :message => "claimed_recording could not be deleted" }, :status => 403
end
end
private
def look_up_claimed_recording
@claimed_recording = ClaimedRecording.find(params[id])
@claimed_recording = ClaimedRecording.find(params[:id])
if @claimed_recording.nil? || @claimed_recording.user_id != current_user.id
render :json => { :message => "claimed_recording not found" }, :status => 404
end

View File

@ -7,7 +7,12 @@ class ApiRecordingsController < ApiController
respond_to :json
# Returns all files this user should have synced down to his computer
def file_list
def list
begin
render :json => Recording.list(current_user), :status => 200
rescue
render :json => { :message => "could not produce list of files" }, :status => 403
end
end
def start

View File

@ -0,0 +1,3 @@
object @claimed_recordings
extends "api_claimed_recordings/show"

View File

@ -0,0 +1,29 @@
# I'm not sure this is right at all. The idea is to bring in all the stuff you would need to play the tracks.
# I don't think I need to include URLs since that's handled by syncing. This is jsut to make the metadata
# depictable.
object @claimed_recording
attributes :id, :name, :is_public, :is_downloadable
child(:recording => :recording) {
attributes :id, :created_at, :duration
child(:band => :band) {
attributes :id, :name
}
child(:mixes => :mixes) {
attributes :id, :url, :is_completed
}
}
child(:recorded_tracks => :recorded_tracks) {
attributes :id, :fully_uploaded, :url
child(:instrument => :instrument) {
attributes :id, :description
}
child(:user => :user) {
attributes :id, :email, :first_name, :last_name, :city, :state, :country, :photo_url
}
}

View File

@ -210,24 +210,25 @@ SampleApp::Application.routes.draw do
match '/cities' => 'api_maxmind_requests#cities', :via => :get
# Recordings
match '/recordings/start' => 'api_recordings_controller#start', :via => :post
match '/recordings/:id/stop' => 'api_recordings_controller#stop', :via => :put
match '/recordings/:id/claim' => 'api_claimed_recordings_controller#claim', :via => :post
match '/recordings/upload_next_part' => 'api_recordings_controller#upload_next_part', :via => :get
match '/recordings/upload_sign' => 'api_recordings_controller#upload_sign', :via => :get
match '/recordings/upload_part_complete' => 'api_recordings_controller#upload_part_complete', :via => :put
match '/recordings/upload_complete' => 'api_recordings_controller#upload_complete', :via => :put
match '/recordings/list' => 'api_recordings#list', :via => :get
match '/recordings/start' => 'api_recordings#start', :via => :post
match '/recordings/:id/stop' => 'api_recordings#stop', :via => :put
match '/recordings/:id/claim' => 'api_recordings#claim', :via => :post
match '/recordings/upload_next_part' => 'api_recordings#upload_next_part', :via => :get
match '/recordings/upload_sign' => 'api_recordings#upload_sign', :via => :get
match '/recordings/upload_part_complete' => 'api_recordings#upload_part_complete', :via => :put
match '/recordings/upload_complete' => 'api_recordings#upload_complete', :via => :put
# Claimed Recordings
match '/claimed_recordings' => 'api_claimed_recordings_controller#index', :via => :get
match '/claimed_recordings/:id' => 'api_claimed_recordings_controller#show', :via => :get
match '/claimed_recordings/:id' => 'api_recordings_controller#update', :via => :put
match '/claimed_recordings/:id' => 'api_recordings_controller#delete', :via => :delete
match '/claimed_recordings' => 'api_claimed_recordings#index', :via => :get
match '/claimed_recordings/:id' => 'api_claimed_recordings#show', :via => :get
match '/claimed_recordings/:id' => 'api_claimed_recordings#update', :via => :put
match '/claimed_recordings/:id' => 'api_claimed_recordings#delete', :via => :delete
# Mixes
match '/mixes/schedule' => 'api_mixes_controller#schedule', :via => :post
match '/mixes/next' => 'api_mixes_controller#next', :via => :get
match '/mixes/finish' => 'api_mixes_controller#finish', :via => :put
match '/mixes/schedule' => 'api_mixes#schedule', :via => :post
match '/mixes/next' => 'api_mixes#next', :via => :get
match '/mixes/finish' => 'api_mixes#finish', :via => :put
# version check for JamClient
match '/versioncheck' => 'artifacts#versioncheck'

View File

@ -0,0 +1,103 @@
require 'spec_helper'
describe ApiClaimedRecordingsController do
render_views
before(:each) do
S3Manager.set_unit_test
@user = FactoryGirl.create(:user)
@connection = FactoryGirl.create(:connection, :user => @user)
@instrument = FactoryGirl.create(:instrument, :description => 'a great instrument')
@track = FactoryGirl.create(:track, :connection => @connection, :instrument => @instrument)
@music_session = FactoryGirl.create(:music_session, :creator => @user, :musician_access => true)
@music_session.connections << @connection
@music_session.save
@recording = Recording.start(@music_session.id, @user)
@recording.stop
@recording.reload
@genre = FactoryGirl.create(:genre)
@recording.claim(@user, "name", @genre, true, true)
@recording.reload
@claimed_recording = @recording.claimed_recordings.first
end
describe "GET 'show'" do
it "should show the right thing when one recording just finished" do
controller.current_user = @user
get :show, :id => @claimed_recording.id
# puts response.body
response.should be_success
json = JSON.parse(response.body)
json.should_not be_nil
json["id"].should == @claimed_recording.id
json["name"].should == @claimed_recording.name
json["recording"]["id"].should == @recording.id
json["recording"]["mixes"].length.should == 0
json["recording"]["band"].should be_nil
json["recorded_tracks"].length.should == 1
json["recorded_tracks"].first["id"].should == @recording.recorded_tracks.first.id
json["recorded_tracks"].first["url"].should == @recording.recorded_tracks.first.url
json["recorded_tracks"].first["instrument"]["id"].should == @instrument.id
json["recorded_tracks"].first["user"]["id"].should == @user.id
end
it "should show the right thing when one recording was just uploaded" do
@recording.recorded_tracks.first.upload_complete
controller.current_user = @user
get :show, :id => @claimed_recording.id
response.should be_success
json = JSON.parse(response.body)
json.should_not be_nil
json["recording"]["mixes"].length.should == 1
json["recording"]["mixes"].first["id"].should == @recording.mixes.first.id
json["recording"]["mixes"].first["url"].should == @recording.mixes.first.url
json["recording"]["mixes"].first["is_completed"].should == false
end
it "should show the right thing when the mix was just uploaded" do
@recording.recorded_tracks.first.upload_complete
@mix = Mix.next("server")
@mix.finish(10000, "md5")
controller.current_user = @user
get :show, :id => @claimed_recording.id
response.should be_success
json = JSON.parse(response.body)
json.should_not be_nil
json["recording"]["mixes"].length.should == 1
json["recording"]["mixes"].first["id"].should == @recording.mixes.first.id
json["recording"]["mixes"].first["is_completed"].should == true
end
end
describe "GET 'index'" do
it "should generate a single output" do
controller.current_user = @user
get :index
response.should be_success
json = JSON.parse(response.body)
json.should_not be_nil
json.length.should == 1
json.first["id"].should == @claimed_recording.id
end
end
=begin
We can't test these because rspec doesn't like that we return 204. It causes rails to return a 406.
describe "DELETE 'destroy'" do
it "should delete properly" do
controller.current_user = @user
delete :delete, :id => @claimed_recording.id
puts response
puts response.body
response.should be_success
expect { ClaimedRecording.find(@claimed_recording.id) }.to raise_error
end
end
=end
end

View File

@ -113,5 +113,14 @@ FactoryGirl.define do
priority 0
end
factory :track, :class => JamRuby::Track do
sound "mono"
end
factory :recorded_track, :class => JamRuby::RecordedTrack do
end
end