Skip to content

Commit

Permalink
Merge pull request #60 from Code-the-Dream-School/HER-54-notify-users…
Browse files Browse the repository at this point in the history
…-of-booking-status

Her 54 notify users of booking status
  • Loading branch information
olesiamironenko authored Jan 17, 2025
2 parents f03fce4 + 9645763 commit 98fd161
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
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

0 comments on commit 98fd161

Please sign in to comment.