diff --git a/app/controllers/api/v1/bookings_controller.rb b/app/controllers/api/v1/bookings_controller.rb index 06ee057f..27e3c18b 100644 --- a/app/controllers/api/v1/bookings_controller.rb +++ b/app/controllers/api/v1/bookings_controller.rb @@ -15,6 +15,8 @@ def create @booking.user = current_user if @booking.save + BookingMailer.booking_confirmation(@booking.user, @booking).deliver_now + BookingMailer.new_booking_notification(@booking.speaker, @booking).deliver_now render json: @booking, status: :created else render json: @booking.errors, status: :unprocessable_entity @@ -22,6 +24,9 @@ def create end def update + booking = Booking.find(params[:id]) + availability = booking.availability + if @booking.update(booking_params) render json: @booking else @@ -32,6 +37,6 @@ def update private def booking_params - params.require(:booking).permit(:event_id, :availability_id, :start_time, :end_time, :status) + params.require(:booking).permit(:event_id, :availability_id, :start_time, :end_time, :location, :status) end end diff --git a/app/mailers/booking_mailer.rb b/app/mailers/booking_mailer.rb new file mode 100644 index 00000000..50f48366 --- /dev/null +++ b/app/mailers/booking_mailer.rb @@ -0,0 +1,17 @@ +class BookingMailer < ApplicationMailer + default from: "no-reply@example.com" + + def booking_confirmation(user, booking) + @user = user + @booking = booking + @order = @booking.order + mail(to: @user.email, subject: "Booking Request Confirmation") + end + + def new_booking_notification(speaker, booking) + @speaker = speaker + @booking = booking + @order = @booking.order + mail(to: @speaker.email, subject: "New Booking Request") + end +end diff --git a/app/views/booking_mailer/booking_confirmation.html.erb b/app/views/booking_mailer/booking_confirmation.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/app/views/booking_mailer/new_booking_notification.html.erb b/app/views/booking_mailer/new_booking_notification.html.erb new file mode 100644 index 00000000..e69de29b diff --git a/spec/mailers/booking_mailer_spec.rb b/spec/mailers/booking_mailer_spec.rb new file mode 100644 index 00000000..fe67407a --- /dev/null +++ b/spec/mailers/booking_mailer_spec.rb @@ -0,0 +1,5 @@ +require "rails_helper" + +RSpec.describe BookingMailer, type: :mailer do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/mailers/previews/booking_mailer_preview.rb b/spec/mailers/previews/booking_mailer_preview.rb new file mode 100644 index 00000000..d54e7191 --- /dev/null +++ b/spec/mailers/previews/booking_mailer_preview.rb @@ -0,0 +1,3 @@ +# Preview all emails at http://localhost:3000/rails/mailers/booking_mailer_mailer +class BookingMailerPreview < ActionMailer::Preview +end