VRFS-1690 VRFS-1691 VRFS-1692 RSVP API work
This commit is contained in:
parent
d11261c5c6
commit
96f62b1364
|
|
@ -769,7 +769,7 @@ module JamRuby
|
|||
|
||||
return if music_session.nil?
|
||||
|
||||
rsvp_requests = RsvpRequest.requests_by_session(music_session)
|
||||
rsvp_requests = RsvpRequest.index(music_session)
|
||||
|
||||
rsvp_requests.each do |rsvp|
|
||||
target_user = rsvp.user
|
||||
|
|
@ -810,7 +810,7 @@ module JamRuby
|
|||
|
||||
return if music_session.nil?
|
||||
|
||||
rsvp_requests = RsvpRequest.requests_by_session(music_session)
|
||||
rsvp_requests = RsvpRequest.index(music_session)
|
||||
|
||||
rsvp_requests.each do |rsvp|
|
||||
target_user = rsvp.user
|
||||
|
|
@ -851,7 +851,7 @@ module JamRuby
|
|||
|
||||
return if music_session.nil?
|
||||
|
||||
rsvp_requests = RsvpRequest.requests_by_session(music_session)
|
||||
rsvp_requests = RsvpRequest.index(music_session)
|
||||
|
||||
rsvp_requests.each do |rsvp|
|
||||
target_user = rsvp.user
|
||||
|
|
@ -888,15 +888,15 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
def send_scheduled_session_comment(music_session, comment)
|
||||
def send_scheduled_session_comment(music_session, creator, comment)
|
||||
|
||||
return if music_session.nil? || comment.blank?
|
||||
|
||||
rsvp_requests = RsvpRequest.requests_by_session(music_session)
|
||||
rsvp_requests = RsvpRequest.index(music_session)
|
||||
|
||||
rsvp_requests.each do |rsvp|
|
||||
target_user = rsvp.user
|
||||
source_user = music_session.creator
|
||||
source_user = creator
|
||||
|
||||
notification = Notification.new
|
||||
notification.description = NotificationTypes::SCHEDULED_SESSION_CANCELLED
|
||||
|
|
|
|||
|
|
@ -4,19 +4,10 @@ module JamRuby
|
|||
belongs_to :user, :class_name => "JamRuby::User"
|
||||
has_many :rsvp_request_rsvp_slots, :class_name => "JamRuby::RsvpRequestRsvpSlot"
|
||||
has_many :rsvp_slots, :class_name => "JamRuby::RsvpSlot", :through => :rsvp_requests_rsvp_slots
|
||||
|
||||
# validates :message, length: {maximum: 1000}, no_profanity: true
|
||||
|
||||
validates :canceled, :inclusion => {:in => [nil, true, false]}
|
||||
|
||||
# def self.create(params)
|
||||
# # slot_ids =
|
||||
# rsvp = RsvpRequest.new
|
||||
# # rsv
|
||||
# rsvp.save
|
||||
# end
|
||||
|
||||
def self.requests_by_session(session, user = nil)
|
||||
def self.index(session, user = nil)
|
||||
query = RsvpRequest
|
||||
.includes(:user)
|
||||
.joins(
|
||||
|
|
@ -40,6 +31,83 @@ module JamRuby
|
|||
return query
|
||||
end
|
||||
|
||||
def self.create(params, user)
|
||||
if rsvp_request.user_id != user.id
|
||||
raise PermissionError, "Only a session invitee create the RSVP."
|
||||
|
||||
RsvpRequest.transaction do
|
||||
rsvp = RsvpRequest.new
|
||||
|
||||
if params[:slot_ids].blank?
|
||||
raise JamRuby::JamArgumentError.new("You must select at least 1 slot.")
|
||||
end
|
||||
|
||||
slot_ids = params[:slot_ids]
|
||||
|
||||
slot_ids.each do |id|
|
||||
end
|
||||
rsvp.save
|
||||
|
||||
Notification.send_scheduled_session_rsvp()
|
||||
end
|
||||
end
|
||||
|
||||
def self.update(params)
|
||||
|
||||
rsvp_request_id = params[:id]
|
||||
|
||||
if !params[:decision].blank?
|
||||
case params[:decision]
|
||||
when "accept"
|
||||
slot_ids = params[:slot_ids]
|
||||
|
||||
slot_ids.each do |id|
|
||||
request_slot = RsvpRequestRsvpSlot.where("rsvp_request_id = '#{rsvp_request_id}' AND rsvp_slot_id = '#{id}'").first
|
||||
request_slot.rsvp_request_id = rsvp_request_id
|
||||
request_slot.rsvp_slot_id = id
|
||||
request_slot.chosen = true
|
||||
request_slot.save
|
||||
end
|
||||
|
||||
# send notification
|
||||
Notification.send_scheduled_session_rsvp_approved(music_session, user)
|
||||
|
||||
when "reject"
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
raise JamRuby::JamArgumentError.new("Invalid request.")
|
||||
end
|
||||
end
|
||||
|
||||
def self.cancel(rsvp_request, music_session, user, message)
|
||||
if music_session.creator.id != user.id && rsvp_request.user_id != user.id
|
||||
raise PermissionError, "Only the session organizer or RSVP creator can cancel the RSVP."
|
||||
|
||||
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.each do |slot|
|
||||
if slot.chosen
|
||||
slot.chosen = false
|
||||
slot.save
|
||||
end
|
||||
end
|
||||
|
||||
# send notification
|
||||
if music_session.creator.id == user.id
|
||||
Notification.send_scheduled_session_rsvp_cancelled_org(music_session, user)
|
||||
else
|
||||
Notification.send_scheduled_session_rsvp_cancelled(music_session, user)
|
||||
end
|
||||
|
||||
Notification.send_scheduled_session_comment(music_session, user, message)
|
||||
end
|
||||
end
|
||||
|
||||
# XXX we need to validate that only one RsvpRequest.chosen = true for a given RsvpSlot
|
||||
# in other words, you can have many requests to a slot, but only 0 or 1 rsvp_request.chosen = true)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,5 +7,9 @@ module JamRuby
|
|||
has_many :rsvp_requests, :class_name => "JamRuby::RsvpRequest", :through => :rsvp_requests_rsvp_slots
|
||||
|
||||
# TODO: validates :proficiency_level
|
||||
|
||||
def is_chosen
|
||||
RsvpRequestRsvpSlot.exists?("chosen=true AND rsvp_slot_id='#{self.id}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,13 +7,10 @@ module JamRuby
|
|||
|
||||
default_scope order('created_at DESC')
|
||||
|
||||
belongs_to(:music_session,
|
||||
:class_name => "JamRuby::MusicSession",
|
||||
:foreign_key => "music_session_id")
|
||||
belongs_to(:music_session, :class_name => "JamRuby::MusicSession", :foreign_key => "music_session_id")
|
||||
belongs_to(:user, :class_name => "JamRuby::User", :foreign_key => "creator_id")
|
||||
|
||||
belongs_to(:user,
|
||||
:class_name => "JamRuby::User",
|
||||
:foreign_key => "creator_id")
|
||||
# validates :comment, length: {maximum: 1000}, no_profanity: true
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -170,7 +170,7 @@ describe Notification do
|
|||
it "sends no notification if session is nil" do
|
||||
sender = FactoryGirl.create(:user)
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_scheduled_session_rsvp(nil, sender, nil)
|
||||
notification = Notification.send_scheduled_session_rsvp(nil, sender, 'Blah', nil)
|
||||
|
||||
UserMailer.deliveries.length.should == 0
|
||||
calls[:count].should == 0
|
||||
|
|
@ -179,7 +179,7 @@ describe Notification do
|
|||
it "sends no notification if user is nil" do
|
||||
session = FactoryGirl.create(:music_session)
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_scheduled_session_rsvp(session, nil, nil)
|
||||
notification = Notification.send_scheduled_session_rsvp(session, nil, 'Blah', nil)
|
||||
|
||||
UserMailer.deliveries.length.should == 0
|
||||
calls[:count].should == 0
|
||||
|
|
@ -222,7 +222,7 @@ describe Notification do
|
|||
it "sends no notification if session is nil" do
|
||||
sender = FactoryGirl.create(:user)
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_scheduled_session_rsvp_cancelled(nil, sender)
|
||||
notification = Notification.send_scheduled_session_rsvp_cancelled(nil, sender, 'Blah')
|
||||
|
||||
UserMailer.deliveries.length.should == 0
|
||||
calls[:count].should == 0
|
||||
|
|
@ -231,7 +231,7 @@ describe Notification do
|
|||
it "sends no notification if user is nil" do
|
||||
session = FactoryGirl.create(:music_session)
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_scheduled_session_rsvp_cancelled(session, nil)
|
||||
notification = Notification.send_scheduled_session_rsvp_cancelled(session, nil, 'Blah')
|
||||
|
||||
UserMailer.deliveries.length.should == 0
|
||||
calls[:count].should == 0
|
||||
|
|
@ -248,7 +248,7 @@ describe Notification do
|
|||
it "sends no notification if session is nil" do
|
||||
receiver = FactoryGirl.create(:user)
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_scheduled_session_rsvp_cancelled_org(nil, receiver)
|
||||
notification = Notification.send_scheduled_session_rsvp_cancelled_org(nil, receiver, 'Blah')
|
||||
|
||||
UserMailer.deliveries.length.should == 0
|
||||
calls[:count].should == 0
|
||||
|
|
@ -257,7 +257,7 @@ describe Notification do
|
|||
it "sends no notification if user is nil" do
|
||||
session = FactoryGirl.create(:music_session)
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_scheduled_session_rsvp_cancelled_org(session, nil)
|
||||
notification = Notification.send_scheduled_session_rsvp_cancelled_org(session, nil, 'Blah')
|
||||
|
||||
UserMailer.deliveries.length.should == 0
|
||||
calls[:count].should == 0
|
||||
|
|
@ -355,9 +355,10 @@ describe Notification do
|
|||
end
|
||||
|
||||
it "sends no notification if comment is empty" do
|
||||
sender = FactoryGirl.create(:user)
|
||||
session = FactoryGirl.create(:music_session)
|
||||
calls = count_publish_to_user_calls
|
||||
notification = Notification.send_scheduled_session_comment(session, '')
|
||||
notification = Notification.send_scheduled_session_comment(session, sender, '')
|
||||
|
||||
UserMailer.deliveries.length.should == 0
|
||||
calls[:count].should == 0
|
||||
|
|
|
|||
|
|
@ -1,9 +1,53 @@
|
|||
class ApiRsvpRequestsController < ApiController
|
||||
|
||||
before_filter :auth_user
|
||||
|
||||
respond_to :json
|
||||
|
||||
def create
|
||||
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 requests for this session
|
||||
if music_session.creator.id == current_user.id
|
||||
@rsvp_requests = RsvpRequest.index(music_session)
|
||||
|
||||
# scope the response to the current user
|
||||
else
|
||||
@rsvp_requests = RsvpRequest.index(music_session, current_user)
|
||||
end
|
||||
|
||||
respond_with @rsvp_requests, 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
|
||||
music_session = MusicSession.find(params[:session_id])
|
||||
@rsvp = RsvpRequest.create(params, current_user)
|
||||
respond_with @rsvp, responder: ApiResponder, :status => 201
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@rsvp_request = RsvpRequest.find(params[:id])
|
||||
respond_with @rsvp_request, responder: ApiResponder, :status => 200
|
||||
end
|
||||
|
||||
def destroy
|
||||
if params[:id].blank? || params[:session_id].blank?
|
||||
render :json => {:message => "RSVP request ID and session ID are required."}, :status => 400
|
||||
else
|
||||
music_session = MusicSession.find(params[:session_id])
|
||||
rsvp_request = RsvpRequest.find(params[:id])
|
||||
RsvpRequest.cancel(rsvp_request, music_session, current_user, params[:message])
|
||||
respond_with responder: ApiResponder, :status => 204
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -167,7 +167,7 @@ SampleApp::Application.routes.draw do
|
|||
match '/sessions/:id/tracks/:track_id' => 'api_music_sessions#track_destroy', :via => :delete
|
||||
|
||||
# RSVP requests
|
||||
match '/sessions/:id/rsvp_requests' => 'api_music_sessions#rsvp_requests_index', :via => :get
|
||||
match '/rsvp_requests' => 'api_rsvp_requests#rsvp_requests_index', :via => :get
|
||||
match '/rsvp_requests' => 'api_rsvp_requests#create', :via => :post
|
||||
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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe "RSVP Request API ", :type => :api do
|
||||
|
||||
include Rack::Test::Methods
|
||||
|
||||
subject { page }
|
||||
|
||||
before(:each) do
|
||||
MusicSession.delete_all
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
it "should prevent request without session ID" do
|
||||
end
|
||||
|
||||
it "should allow session creator to view all" do
|
||||
end
|
||||
|
||||
it "should allow RSVP creator to view only his list" do
|
||||
end
|
||||
|
||||
it "should allow others to view list" do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "create" do
|
||||
it "should allow session invitee to create RSVP" do
|
||||
end
|
||||
|
||||
it "should not allow non-invitee to create RSVP" do
|
||||
end
|
||||
|
||||
it "should require at least 1 slot selection" do
|
||||
end
|
||||
|
||||
it "should prevent RSVP for chosen slot" do
|
||||
end
|
||||
end
|
||||
|
||||
describe "show" do
|
||||
it "should allow RSVP creator to view" do
|
||||
end
|
||||
|
||||
it "should allow session creator to view" do
|
||||
end
|
||||
|
||||
it "should allow anyone else to view" do
|
||||
end
|
||||
end
|
||||
|
||||
describe "destroy" do
|
||||
it "should allow RSVP creator to cancel" do
|
||||
end
|
||||
|
||||
it "should allow session creator to cancel" do
|
||||
end
|
||||
|
||||
it "should not allow anyone else to cancel" do
|
||||
end
|
||||
|
||||
it "should set chosen to false on all slots" do
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Reference in New Issue