This repository contains a Django-Rest-Framework implementation of the back-end API of a jogging tracker app.
- API Users must be able to create an account and log in.
- All API calls must be authenticated.
- Implement at least three roles with different permission levels: a regular user would only be able to CRUD on their owned records, a user manager would be able to CRUD only users, and an admin would be able to CRUD all records and users.
- Each time entry when entered has a date, distance, time, and location.
- Based on the provided date and location, API should connect to a weather API provider and get the weather conditions for the run, and store that with each run.
- The API must create a report on average speed & distance per week.
- The API must be able to return data in the JSON format.
- The API should provide filter capabilities for all endpoints that return a list of elements, as well should be able to support pagination.
- The API filtering should allow using parenthesis for defining operations precedence and use any combination of the available fields. The supported operations should at least include or, and, eq (equals), ne (not equals), gt (greater than), lt (lower than). Example -> (date eq '2016-05-01') AND ((distance gt 20) OR (distance lt 10)).
- Write unit and e2e tests.
- Create the environment from the conda file:
conda env create -f environment.yml - Activate the conda environment:
conda activate toptal - Check all the tests are runing:
python manage.py test api - Run the server:
python manage.py runserver. By default, the server link ishttp://127.0.0.1:8000/ - There are 2 parent endpoints:
api/andadmin.adminis used in order to login with a superuser. - The
apiendpoint contains all the jogging application endpoints. They can be viewed here
- Register by creating a
POSTrequest toapi/userwith body{'first_name': 'user', 'last_name': 'user', 'email': 'user@user.com', 'password': 'user' , 'username': 'user'} - Get login authentication token by creating a
POSTrequest toapi/token-authwith the body{'password': 'user' , 'username': 'user'} - Add the authentication token to Postman Headers:
AuthorizationToken <token_value> - Create a Jog by sending a
POSTrequest toapi/jogswith body{'date': '2020-04-23', 'distance:' 50, 'time': 50 'location': 'Amsterdam', 'user_id': <your_user_id>}. The weather will be filled automatically by the API. - Once you added multiple jogs, view your weekly report by sending a
GETrequest toapi/weekly_report. You can change the date by specifying thedateparameter .
Enjoy!