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

Conversation

olesiamironenko
Copy link
Collaborator

@olesiamironenko olesiamironenko commented Jan 16, 2025

Issue HER-54: Notify Users of Booking Status

https://raquelanaroman.atlassian.net/browse/HER-54

Description
As a teacher user, I want to be notified by email when a booking has been successfully submitted so that I have a record of my booking.

As a speaker user, I want to be notified by email when a booking has been created so that I can review the details and confirm or decline the booking.

Acceptance Criteria

Mailer Setup:

A mailer named BookingMailer should be generated.

The BookingMailer should have two methods:

booking_confirmation(user, booking): Sends a confirmation email to the user (teacher) with the subject "Booking Request Confirmation".

new_booking_notification(speaker, booking): Sends a notification email to the speaker with the subject "New Booking Request".

Controller Logic:

The BookingsController should be updated to send emails when a booking is created.

When a booking is successfully created, the following emails should be sent:

A confirmation email to the user (teacher) using BookingMailer.booking_confirmation.

A notification email to the speaker using BookingMailer.new_booking_notification.

Booking Creation:

The create action in the BookingsController should permit the following parameters: :event_id, :start_time, :end_time, :location.

Upon successful creation of a booking, the mailers should be triggered to send the appropriate emails.

Testing:

Tests should be written to ensure that the mailers are correctly triggered and that the emails contain the expected content.

Tests should verify that the Booking model relationships are correctly set up and that the BookingsController handles booking creation and email sending as expected.

Implementation

Generate a Mailer:

rails generate mailer BookingMailer

Define the Mailer:

class BookingMailer < ApplicationMailer
  def booking_request_confirmation(booking)
    @user = booking.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

Call the Mailer in the Controller: Update the controller to send the emails when a booking is created.

def create
  @booking = Booking.new(booking_params)
  if @booking.save
    BookingMailer.booking_confirmation(@booking.user, @booking).deliver_now
    BookingMailer.new_booking_notification(@booking.speaker, @booking).deliver_now
    # Other logic
  else
    # Handle failure
  end
end

Changes

  1. Generated mailer.
  2. Defined BookingMailer.
  3. Booking controller updated.
  4. Updated booking controller permitted params.
  5. Created booking mailer templates.

Review Checklist

  • I have documented my code with code comments.

Copy link
Collaborator

@dewi-anggraini dewi-anggraini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

@olesiamironenko olesiamironenko merged commit 98fd161 into main Jan 17, 2025
3 checks passed
@olesiamironenko olesiamironenko deleted the HER-54-notify-users-of-booking-status branch January 17, 2025 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants