VRFS-1739 API for RSVP slots

This commit is contained in:
Brian Smith 2014-05-21 01:36:32 -04:00
parent f793b14879
commit 7f5940ac01
8 changed files with 78 additions and 9 deletions

View File

@ -7,8 +7,9 @@ module JamRuby
validates :canceled, :inclusion => {:in => [nil, true, false]}
def self.index(session, user = nil)
def self.index(music_session, user = nil)
query = RsvpRequest
.includes(:user)
.joins(
%Q{
INNER JOIN
@ -22,11 +23,11 @@ module JamRuby
)
.where(
%Q{
rs.music_session_id = '#{session.id}'
rs.music_session_id = '#{music_session.id}'
}
)
query = query.where("rsvp_requests.user_id = '?'", user.id) unless user.nil?
query = query.where("rsvp_requests.user_id = ?", user.id) unless user.nil?
return query.uniq
end
@ -39,7 +40,7 @@ module JamRuby
end
# verify invitation exists for this user and session
invitation = Invitation.where("music_session_id = '?' AND receiver_id = '?'", music_session.id, user.id)
invitation = Invitation.where("music_session_id = ? AND receiver_id = ?", music_session.id, user.id)
if invitation.blank?
raise PermissionError, "Only a session invitee can create an RSVP."
@ -142,7 +143,7 @@ module JamRuby
RsvpRequest.transaction do
# mark corresponding slot's chosen field as false
rsvp_request_slots = RsvpRequestRsvpSlot.find("rsvp_request_id = '?'", rsvp_request.id)
rsvp_request_slots = RsvpRequestRsvpSlot.find("rsvp_request_id = ?", rsvp_request.id)
rsvp_request_slots.each do |slot|
if slot.chosen

View File

@ -6,10 +6,17 @@ module JamRuby
has_many :rsvp_requests_rsvp_slots, :class_name => "JamRuby::RsvpRequestRsvpSlot", :foreign_key => "rsvp_slot_id"
has_many :rsvp_requests, :class_name => "JamRuby::RsvpRequest", :through => :rsvp_requests_rsvp_slots
attr_accessor :chosen
# TODO: validates :proficiency_level
def is_chosen
RsvpRequestRsvpSlot.exists?("chosen = true AND rsvp_slot_id = '?'", self.id)
def self.index(music_session)
RsvpSlot.where("music_session_id = ?", music_session.id)
end
def chosen
chosen_slots = RsvpRequestRsvpSlot.where("chosen = true AND rsvp_slot_id = ?", self.id)
!chosen_slots.blank?
end
end
end

View File

@ -5,8 +5,10 @@ class ApiRsvpRequestsController < ApiController
respond_to :json
def index
if params[:session_id].blank?
render :json => {:message => "Session ID is required"}, :status => 400
else
music_session = MusicSession.find(params[:session_id])
@ -22,6 +24,7 @@ class ApiRsvpRequestsController < ApiController
respond_with @rsvp_requests, responder: ApiResponder, :status => 200
end
end
def create

View File

@ -0,0 +1,32 @@
class ApiRsvpSlotsController < ApiController
# before_filter :auth_user
respond_to :json
def index
if params[:session_id].blank?
render :json => {:message => "Session ID is required"}, :status => 400
else
music_session = MusicSession.find(params[:session_id])
# retrieve all slots for this session
@rsvp_slots = RsvpSlot.index(music_session)
respond_with @rsvp_slots, responder: ApiResponder, :status => 200
end
end
# def create
# if params[:id].blank? || params[:session_id].blank?
# render :json => {:message => "Session ID is required."}, :status => 400
# else
# @rsvp = RsvpRequest.create(params, current_user)
# respond_with @rsvp, responder: ApiResponder, :status => 201
# end
# end
end

View File

@ -1,9 +1,9 @@
object @rsvp_request
attributes :id, :user_id, :canceled, :created_at
attributes :id, :canceled, :created_at
child(:user => :user) {
attributes :name, :photo_url
attributes :id, :name, :photo_url
}
child(:rsvp_slots => :rsvp_slots) {

View File

@ -0,0 +1,3 @@
object @rsvp_slots
extends "api_rsvp_slots/show"

View File

@ -0,0 +1,19 @@
object @rsvp_slot
attributes :id, :instrument_id, :proficiency_level, :chosen
child(:music_session => :music_session) {
attributes :id, :description, :scheduled_start, :recurring_mode
}
child(:rsvp_requests => :rsvp_requests) {
attributes :id, :canceled
child(:user => :user) {
attributes :id, :name, :photo_url
}
}
child(:rsvp_requests_rsvp_slots => :rsvp_requests_rsvp_slots) {
attributes :id, :chosen
}

View File

@ -173,6 +173,10 @@ SampleApp::Application.routes.draw do
match '/rsvp_requests/:id' => 'api_rsvp_requests#show', :via => :get, :as => 'api_rsvp_request_detail'
match '/rsvp_requests/:id' => 'api_rsvp_requests#destroy', :via => :delete
# RSVP slots
match '/rsvp_slots' => 'api_rsvp_slots#index', :via => :get
match '/rsvp_slots/:id' => 'api_rsvp_slots#show', :via => :get, :as => 'api_rsvp_slot_detail'
# music session playback recording state
match '/sessions/:id/claimed_recording/:claimed_recording_id/start' => 'api_music_sessions#claimed_recording_start', :via => :post
match '/sessions/:id/claimed_recording/:claimed_recording_id/stop' => 'api_music_sessions#claimed_recording_stop', :via => :post