Skip to content

Nessvah/little-lemon-api

Repository files navigation

Little Lemon Restaurant API

This project is an API built using Django REST Framework for managing table bookings for the Little Lemon restaurant. The API allows users to perform CRUD (Create, Read, Update, Delete) operations on booking data, enabling the restaurant to efficiently manage reservations.

Features

  • Authentication: Users can authenticate using username and password to access protected endpoints.
  • Booking Management: Users can create, view, update, and delete bookings.
  • Permissions: Different permission levels are enforced to ensure that only authorized users can perform certain actions (e.g., only administrators can delete bookings).
  • Validation: Input data is validated to ensure it meets specified criteria (e.g., date and time format for bookings).
  • API Documentation: The API provides documentation for endpoints, request methods, and required parameters.
  • Database Integration: The API integrates with a MySQL database to store booking information.

Installation

To run this project locally, follow these steps:

  • Clone the repository:
git clone https://github.com/Nessvah/little-lemon-api.git
  • Navigate to the project directory:
cd little-lemon-api
  • Install dependencies:
pip install -r requirements.txt
  • Create MySQL database and user:
create database littlelemon;
use littlelemon;
CREATE USER 'admindjango'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON littlelemon.* TO 'admindjango'@'localhost';
  • Make a .env for your environment variables and follow the env.example:
DB_USER=user
DB_PASSWORD=password
DB_PORT=3306 // default is 3306 change if otherwise
DB_DATABASE=databaseName
DB_HOST=localhost  // default localhost change if otherwise

Otherwise, just set it up on the settings in the DATABASES with your own values

  • Run migrations to create the database schema:
python manage.py migrate
  • Create a superuser for accessing the Django admin interface and test the permissions for admins:
python manage.py createsuperuser
#username: admin
#email: admin@example.com
#password: admin@123!
  • Start the development server:
python manage.py runserver
  • Access the API at http://localhost:800/api/
  • Access the Django admin interface at http://localhost:8000/admin/ and log in using the credentials you created in step 5.

Usage

  • Authentication: Before accessing protected endpoints, users need to authenticate by providing their username and password.
  • Testing: Run tests using python manage.py test tests.

Endpoints for menu items and bookings

Endpoint URL Method Admin Permissions User Permissions
List Bookings /api/restaurant/bookings/ GET Full access View own bookings
Create Booking /api/restaurant/bookings/ POST Full access Create own bookings
Retrieve Booking /api/restaurant/bookings/<booking_id>/ GET Full access View own booking details
Update Booking /api/restaurant/bookings/<booking_id>/ PUT, PATCH Full access Update own booking details
Delete Booking /api/restaurant/bookings/<booking_id>/ DELETE Full access Delete own bookings
List Menu Items /api/restaurant/menu/ GET Full access View menu items
Create Menu Item /api/restaurant/menu/ POST Full access No permission (only admins)
Retrieve Menu Item /api/restaurant/menu/<menu_item_id>/ GET Full access View menu items
Update Menu Item /api/restaurant/menu/<menu_item_id>/ PUT, PATCH Full access No permission (only admins)
Delete Menu Item /api/restaurant/menu/<menu_item_id>/ DELETE Full access No permission (only admins)

For creating bookings:

{
	"name": "Aline",
	"no_of_guests": "5",
	"booking_date": "2024-02-11"
}

For creating menu items

{
   "title": "Grilled fish",
   "price": 16.99,
   "inventory": 20
}

Endpoints for authentication

Endpoint URL Method Description Permissions
User Registration /api/auth/users/ POST Register a new user account. Public access
User Login /api/auth/token/login/ POST Obtain a JWT authentication token. Public access
User Profile /api/auth/users/me/ GET, PUT, PATCH Retrieve or update the user's profile. Authenticated users only

For user registration

{
	"email": "email@example.com",
	"password":"password",
	"username":"username"
}

For login

{
	"username": "username",
	"password": "password"
}

Endpoint for testing static files:

http://127.0.0.1:8000/api/restaurant/

Contributing

Contributions are welcome! If you have any suggestions or find any issues, please create a GitHub issue or submit a pull request.

License

This project is licensed under the GNU GENERAL PUBLIC LICENSE - see the LICENSE file for details.

Acknowledgments

Special thanks to Meta Back-End Developer for providing guidance and resources.

About

API built using Django REST Framework for managing table bookings for the Little Lemon restaurant.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published