Have you guys ever hear about Calendly? From this app, I have an idea to make the app called Bookme.
First, When I started making this app, I thought I would do an app for some practice with Ruby and React JS and wanted to have a conversation with me about the job, they could book me through the app.
Bookme App is an app for scheduling appointments, meetings, and events. People can book you for a meeting you've created. Even more, people can book you through this Booking App instead of email or message.
The Bookme App only allows you to create and delete meetings, Invitees will see all the meetings you've available in my schedule, and they can select one of those to make an appointment with you. After a person has booked you, it will have the email notice for you and the person who has booked you, Ensuring the ideal time slot for both parties.
For this Booking App, I'll be creating an API containing Meeting and Booking. We'll be using PostgreSQL for our database cause it will allow easier to push it on Heroku.
To get started, we will create the Rails API.
rails new booking_backend --api --database=postgresql
rails new booking_backend command will create the full application with views and some we won't be using, so we insert the
--api to specify it is an API.
--database= the database we are using, which is
Once you've created it, you can open the project in your code editor. Inside the
app folder, we will be working on the
First, we will generate two models are Meeting and Booking.
rails generate model Meeting title:string start_date:datetime end_date:datetime start_time:time end_time:time time_meeting:string
This command line will create the migrate, the meeting files, and some other code.
In our meeting will have:
titleof the meeting.
end_dateis the valid date of the meeting.
end_timeis the available time people can book the meeting in the day.
time_meetingis the limited time of the meeting.
rails generate model Booking meeting:references name:string date:date time:time email:string message:text
This command line will create the migrate, booking files, and some other code.
In our Booking table will have some columns for people to book the meeting:
timeare the day and time the person booking wants to start the meeting.
messageis the message of the person booking to send to the meeting user.
meeting:references creates a relationship with the Meeting model, this is because of our Booking to
belong_to :meeting and Meeting
Once we have everything done, we can start building and migrating our database with the following commands:
//Set up the database rails db:setup //Run the migration files rails db:migrate
class Meeting < ApplicationRecord has_many :bookings validates :title, :time_meeting, :start_date, :end_date, :start_time, :end_time, :user_id, presence: true end
Because booking belongs to a meeting, it's mean the meeting will have many bookings
validates :title, :time_meeting...are used to ensure that valid data of
:title, :time_meeting...is saved into database
:title, :time_meeting, :start_date, :end_date, :start_time, :end_time, :user_id,are column in meeting table.
presence: trueis a method to check if the value is nil or a blank string,
Add code to the Booking Model:
class Booking < ApplicationRecord belongs_to :meeting, optional: true validates :name, :date, :time, :email, :message, presence: true end
- As I told you before, the meeting has many bookings, it means booking will belong to meeting