Django application with an API that receives a set of points on a grid as semicolon separated values. And then it finds the points that are closest to each other. Store the received set of points and the closest points on a DB.
This assumes that you are running on any *nix environment and have Python 3.10+ and git installed in your local machine.
- Clone the repository
$ git clone [email protected]:ageeknamedslickback/closest-points.git
$ cd closest-points
- Create and activate a virtual environment to run your code
$ python3 -m venv <name of your venv>
$ source <name of your venv>/bin/activate
- Install dependancies
$ pip3 install -r requirements.txt
- Create an env.sh file and add the following
export SECRET_KEY="<your secret key>"
export DEBUG="true"
- Remeber to source your environment variables
$ source env.sh
- Run migrations (code uses SQLite thus no further configs) and the server
$ python3 manage.py migrate
$ python3 manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
May 18, 2023 - 21:47:51
Django version 4.2.1, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
$ tox -r
Path | Method | Description |
/api/v1/closest-points | POST | Calculates and store a set of points and the closest points in the set |
{
"points_set": "2,2;-1,30;20,11;4,5"
}
{
"points_set": "2,2;-1,30;20,11;4,5",
"closest_points": "2,2;4,5"
}
curl --location 'http://127.0.0.1:8000/api/v1/closest-points/' \
--header 'Content-Type: application/json' \
--data '{
"points_set": "2,3;4,5;6,7"
}'
Path | Method | Description |
/api/v1/closest-points | GET | Gets all the stored point sets and their closes points |
[
{
"points_set": "2,2;-1,30;20,11;4,5",
"closest_points": "2,2;4,5"
}
]
curl --location 'http://127.0.0.1:8000/api/v1/closest-points/' \
--header 'Content-Type: application/json'
You have the ability to see the data in the database using Django's Admin interface.
- Create a super user
$ python3 manage.py createsuperuser
Username (leave blank to use 'dumbledore'): stewie
Email address: [email protected]
Password:
Password (again):
Superuser created successfully.
- Visit the admin page /admin and login using the above created credentials