Solution to REST API project posted in the MCDA5550 class by Prof. Sanjeevi Ramachandran
- Hotels can be viewed and new hotels can be added into the database.
- Users can book an Hotel by providing the hotel name, check-in date, check-out date and information of the guests.
- Check-in and Check-out date validations are added.
- Check-out date must be greater than the check-in date.
- Check-in date must be greater than the current date.
- Character field validations are added.
- City field in the Hotel model must only contain alphabets.
The first thing to do is to clone the repository:
$ git clone https://github.com/vedantthapa/hotel-reservation.git
$ cd hotel-reservation
Then install the dependencies:
# using pip
$ pip install -r requirements.txt
# using Conda
$ conda create --name <env_name> --file requirements.txt
Once the dependencies has finished downloading, edit your database settings in the DATABASES
dictionary in the hotelsite/settings.py
file.
After configuring the database run the below commands to add tables into the schema.
$ python manage.py makemigrations
$ python manage.py migrate
Now, run the app by executing the following command
$ python manage.py runserver
Access endpoints using Postman or any other API platform to do a GET or POST request.
-
Hotel:
http://127.0.0.1:8000/app/hotels/
-
Booking:
http://127.0.0.1:8000/app/booking/
{
"name": "Hilton",
"email": "hilton@hilton.ca",
"city": "Dartmouth"
}
{
"hotel": "Hilton",
"check_in": "2024-03-08",
"check_out": "2024-03-10",
"guest": [
{
"name": "Mike",
"age": 24,
"email": "mike@gmail.com"
},
{
"name": "Robin",
"age": 39,
"email": "rj@yahoo.com"
}
]
}