This is a RESTful API for a restaurant. It provides endpoints for browsing menu items, managing user carts, placing orders, and administrative tasks. The API supports role-based permissions for customers, managers, and delivery crew.
- Browse menu items and categories.
- User registration and authentication.
- Customers can add/remove items from their cart.
- Customers can place orders from their cart.
- Role-based access control:
- Manager: Full control over menu items, categories, and all orders. Can assign users to delivery crew and other manager roles.
- Delivery Crew: Can view and update the status of orders assigned to them.
- Customer: Can manage their own cart and view their own orders.
- Filtering, searching, and ordering on menu items and orders.
- Pagination and rate limiting
- Django
- Django REST Framework
- Djoser (for user registration and authentication)
- SQLite (for development)
Follow these steps to get the project up and running on your local machine.
- Python 3.8+
- pip
venv(or any other virtual environment tool)
-
Clone the repository:
git clone https://github.com/Mharfe23/Restaurant-django-rest-api cd Restaurant-django-rest-api -
Create and activate a virtual environment:
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install dependencies: install the packages.
pip install django djangorestframework djoser
-
Apply database migrations:
python manage.py makemigrations python manage.py migrate
-
Create user roles: This project uses three roles: Customer, Manager, and Delivery Crew.
- Customers are regular authenticated users.
- Manager and Delivery Crew roles are managed using Django's Group system. You'll need to create these groups.
First, create a superuser to access the admin panel:
python manage.py createsuperuser
Then, run the development server, navigate to the admin panel (
/admin/), and create two groups namedManagerandDelivery-crew. You can then assign users to these groups. -
Run the development server:
python manage.py runserver
The API will be available at
http://127.0.0.1:8000/.
All endpoints are prefixed with /api/.
Djoser is used for handling user registration and authentication. These endpoints are available under /auth/.
| Endpoint | Method | Description |
|---|---|---|
/auth/users/ |
POST |
Register a new user. |
/auth/users/me/ |
GET |
Get current user details. |
/auth/token/login/ |
POST |
Get an authentication token. |
/auth/token/logout/ |
POST |
Invalidate the auth token. |
| Endpoint | Method | Description | Permissions |
|---|---|---|---|
/menu-items/ |
GET, POST |
List or create menu items. | GET: Public, POST: Manager |
/menu-items/{id} |
GET, PUT, PATCH, DELETE |
Retrieve, update or delete a single menu item. | GET: Public, Others: Manager |
/categories/ |
GET, POST |
List or create categories. | GET: Public, POST: Manager |
| Endpoint | Method | Description |
|---|---|---|
/groups/manager/users |
GET, POST |
List or add users to the Manager group. |
/groups/manager/users/{userId} |
DELETE |
Remove a user from the Manager group. |
/groups/delivery-crew/users |
GET, POST |
List or add users to the Delivery Crew group. |
/groups/delivery-crew/users/{userId} |
DELETE |
Remove a user from the Delivery Crew group. |
| Endpoint | Method | Description |
|---|---|---|
/cart/menu-items/ |
GET, POST, DELETE |
List, add, or delete items from the cart. |
| Endpoint | Method | Description | Permissions |
|---|---|---|---|
/orders/ |
GET, POST |
List or create orders. GET depends on role. |
Customer, Manager, Delivery Crew |
/orders/{orderId}/ |
GET, PUT, PATCH, DELETE |
Retrieve, update or delete a single order. | GET: Customer, PUT/PATCH: Manager/Delivery Crew, DELETE: Manager |
- Anonymous Users: Can browse menu items and categories.
- Authenticated Users (Customers):
- Can access all
GETendpoints for menus. - Can manage their own cart.
- Can place orders.
- Can view their own orders.
- Can access all
- Delivery Crew:
- All customer permissions.
- Can view orders assigned to them.
- Can update the status of their assigned orders.
- Managers:
- All permissions.
- Can create, update, and delete menu items and categories.
- Can view all orders.
- Can assign users to Manager and Delivery Crew groups.
- Can assign delivery crew to orders.
- Can delete any order.