Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Her 54 notify users of booking status #60

Merged
merged 8 commits into from
Jan 17, 2025
7 changes: 6 additions & 1 deletion app/controllers/api/v1/bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ 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
end
end

def update
booking = Booking.find(params[:id])
availability = booking.availability

if @booking.update(booking_params)
render json: @booking
else
Expand All @@ -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
17 changes: 17 additions & 0 deletions app/mailers/booking_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class BookingMailer < ApplicationMailer
default from: "[email protected]"

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
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions spec/mailers/booking_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rails_helper"

RSpec.describe BookingMailer, type: :mailer do
pending "add some examples to (or delete) #{__FILE__}"
end
3 changes: 3 additions & 0 deletions spec/mailers/previews/booking_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Preview all emails at http://localhost:3000/rails/mailers/booking_mailer_mailer
class BookingMailerPreview < ActionMailer::Preview
end
Loading