Skip to content

Commit

Permalink
Merge pull request #459 from mehulkar/attendance
Browse files Browse the repository at this point in the history
Attendance emails
  • Loading branch information
mehulkar committed Jun 6, 2015
2 parents 3ca6e7d + 7876b29 commit 921722f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 52 deletions.
26 changes: 26 additions & 0 deletions app/controllers/attendance_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ class AttendanceController < ApplicationController
before_action :host_authorized?, only: [:mark]
before_action :set_attendance, except: [:mark]

# POST /tea_times/1/attendance
def create
@user = current_user
@tea_time = TeaTime.find(params[:id])

@attendance = Attendance.where(tea_time_id: @tea_time.id, user_id: @user.id).first_or_initialize

# Set status
if @attendance.tea_time.spots_remaining?
@attendance.status = :pending
else
@attendance.status = :waiting_list
end

if @attendance.save

@attendance.send_mail

message = @attendance.waiting_list? ?
"You're on the wait list! Check your email for details." :
"You're set for tea time! Check your email and add it to your calendar :)"
return redirect_to profile_path, notice: message
else
return redirect_to city_path(@tea_time.city), alert: "Couldn't register for that, sorry :("
end
end

############################################
# Host-related Attendance Actions
Expand Down
43 changes: 0 additions & 43 deletions app/controllers/tea_times_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,6 @@ def new
def edit
end

# POST /tea_times/1/attendance
def create_attendance
@user = current_user
#FIXME: ALL THIS
if @user.nil?
user_data = GetOrCreateUser.call({nickname: tea_time_params[:nickname],
email: tea_time_params[:email]},
@tea_time.city)

if user_data[:new_user?] && user_data[:user].valid?
@user = user_data[:user]
sign_in @user
elsif !user_data[:new_user?] && user_data[:user].valid?
return redirect_to new_user_session_path, alert: 'You already have an account. Log in! Then register for the tea time.'
end
end

if @user.nil?
return redirect_to tea_time_path(@tea_time), alert: "Sorry, something has gone wrong. Our fault. Try again!"
end


@attendance = Attendance.where(tea_time: @tea_time, user: @user).first_or_initialize
@attendance.try_join

if @attendance.save
@attendance.queue_reminders
message = @attendance.waiting_list? ?
"You're on the wait list! Check your email for details." :
"You're set for tea time! Check your email and add it to your calendar :)"
respond_to do |format|
format.html { return redirect_to profile_path, notice: message }
format.json { @attendance }
end
else
respond_to do |format|
format.html { return redirect_to city_path(@tea_time.city),
alert: "Couldn't register for that, sorry :(" }
format.json { @attendance }
end
end
end

# POST /tea_times
# POST /tea_times.json
def create
Expand Down
8 changes: 0 additions & 8 deletions app/models/attendance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,6 @@ def occurred?
tea_time.occurred?
end

def try_join
if self.tea_time.spots_remaining?
self.status = :pending
else
self.status = :waiting_list
end
end

class << self
def host_statuses
self.statuses.keys - ['waiting_list', 'cancelled', 'pending']
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

resources :tea_times do
member do
post '/attendance' => 'tea_times#create_attendance', as: :attendance
post '/attendance' => 'attendance#create', as: :attendance
patch '/attendance/all' => 'attendance#mark', as: :mark
put '/cancel' => 'tea_times#cancel', as: :cancel
get '/attendance/:attendance_id' => 'attendance#show', as: :show_attendance
Expand Down

0 comments on commit 921722f

Please sign in to comment.