This repository contains the source code for a RESTful API for managing a vending machine system. The API allows users to perform various operations such as user authentication, product management, depositing funds, purchasing products, and resetting deposits.
- User authentication with JWT tokens
- CRUD operations for users and products
- Deposit funds into user accounts
- Purchase products with deposited funds
- Reset user deposits
- Django: Web framework for building the API
- Django REST Framework: Toolkit for building Web APIs
- SQLite: Database management system
- Postman: API development and testing environment
vending_machine_api/
: Main project directoryusers/
: App for managing user operationsmigrations/
: Database migration filestests/
: Test cases for user operations__init__.py
: Initialization file for the appadmin.py
: Admin configurations for user modelsmodels.py
: User model definitionsserializers.py
: Serializers for user modelsurls.py
: URL configurations for user API endpointsviews.py
: Views for handling user operations
products/
: App for managing product operationsmigrations/
: Database migration filestests/
: Test cases for product operations__init__.py
: Initialization file for the appadmin.py
: Admin configurations for product modelsmodels.py
: Product model definitionsserializers.py
: Serializers for product modelsurls.py
: URL configurations for product API endpointsviews.py
: Views for handling product operations
manage.py
: Django command-line utility for administrative tasksrequirements.txt
: List of Python dependencies
-
Clone the repository:
git clone https://github.com/OmarShamkh/vending_machine_api.git
-
Navigate to the project directory:
cd vending-machine-api/
-
Create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
-
Install dependencies:
pip3 install -r requirements.txt
-
Generate a SECRET_KEY for the Django application. You can use a random string generator tool or generate one manually. Replace the placeholder
YOUR_SECRET_KEY_HERE
in the.env.example
file with your generated secret key.mv .env.example .env
-
Run database migrations:
python3 manage.py migrate
-
Start the development server:
python3 manage.py runserver
- Ensure the development server is running.
- Access the API endpoints from https://localhost:8000/api/docs/
GET /api/users/
: Retrieve a list of users.POST /api/users/
: Create a new user.GET /api/users/{id}/
: Retrieve details of a specific user.PUT /api/users/{id}/
: Update details of a specific user.DELETE /api/users/{id}/
: Delete a specific user.POST /api/users/login/
: Authenticat user.POST /api/users/logout/
: Logout user.
GET /api/products/
: Retrieve a list of products.POST /api/products/
: Create a new product.GET /api/products/{id}/
: Retrieve details of a specific product.PUT /api/products/{id}/
: Update details of a specific product.DELETE /api/products/{id}/
: Delete a specific product.
POST /api/users/deposit/
: Deposit funds into the user's account.
POST /api/users/buy/
: Buying products using deposited funds.
POST /api/users/reset-deposit/
: Reset the user's deposit amount.
-
Ensure the development server is running.
-
Run the tests using:
python3 manage.py test users products
You can access the swagger documentation from the following link: https://localhost:8000/api/docs/