This is a Django-based REST API for managing an elevator system.
The application is built using the Django framework and Django Rest Framework. The data is stored in a SQLite database that comes with Django by default. The logic of elevator control is kept in the Elevator model in the elevators app.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
You'll need to have Python 3 and Django installed on your local machine. If you don't have Python or Django installed, you can find the downloads and instructions here:
- Python: https://www.python.org/downloads/
- Django: https://docs.djangoproject.com/en/4.0/intro/install/
-
Clone this repository by running the following command in your terminal:
git clone https://github.com/your_username/elevator-problem.git
-
Navigate into the project directory:
cd elevator_system -
Install the necessary Python packages:
pip install -r requirements.txt
-
Run the migrations:
python manage.py migrate
-
You're ready to go! Start the server:
python manage.py runserver
Below are the available API endpoints and their functions:
GET /elevators/: Fetch all elevatorsGET /elevators/<id>/: Fetch a specific elevatorGET /elevators/<id>/state/: Fetch the state of a specific elevatorGET /elevators/<id>/door/: Fetch the door status of a specific elevatorGET /elevators/<id>/current_floor/: Fetch the current floor of a specific elevatorGET /elevators/<id>/destination_floor/: Fetch the destination floor of a specific elevatorGET /elevators/<id>/requests/: Fetch all requests for a specific elevatorPOST /elevators/: Create an elevatorPOST /elevators/<id>/move_up/: Move a specific elevator up by one floorPOST /elevators/<id>/move_down/: Move a specific elevator down by one floorPOST /elevators/<id>/stop/: Stop a specific elevatorPOST /elevators/<id>/open_door/: Open the door of a specific elevatorPOST /elevators/<id>/close_door/: Close the door of a specific elevatorPOST /elevators/<id>/add_request/: Add a floor request for a specific elevatorPOST /requests/make_request/: Make a floor request
Note: Replace <id> with the actual ID of an elevator.
Open Terminal and Navigate to the project directory 'elevator_system' as above. To run the test_api.py file, type the following command:
bash python3 test_api.py
test_api.py initializes 5 elevators and store their IDs. It also sends GET and POST requests to most of the API endpoints mentioned above.
To run the tests in tests.py, navigate to the project directory and type the following command:
bash python manage.py test
- Python 3 - The programming language used.
- Django - The web framework used.
- Django Rest Framework - Toolkit used to build the API.
- Shranay Agarwal - Initial work - shraag