- Used Trie data structure for storing locations and efficiently retrieving auto complete suggestions.
- Implemented GET API for retrieving suggestions (Does not require authentication).
- Implemented POST APIs for adding location, deleting location, and updating popularity for existing location (All require Authentication).
- Wrote test cases.
- Implemented Rate Limit using ratelimit library to avoid excessive queries.
- Implemented Cache for search query.
- Implemented Token based Authentication for Add, Delete, and Update APIs.
- Implemented automated script for authentication and adding all locations provided in the data file.
-
Steps:-
$ pip install virtualenv$ virtualenv myenv$ myenv\Scripts\activate$ pip install -r requirements.txt -
Steps:-
$ python manage.py makemigrations$ python manage.py migrate$ python manage.py createsuperuser -
$ python manage.py runserver -
$ curl --location --request POST '127.0.0.1:8000/api/login' --form 'username={username}' --form 'password={password}' -
Run script for adding all locations in the data file to database (Update username and password in the file)
$ python script_add_locations.py --file {data file} -
$ curl --location --request GET '127.0.0.1:8000/query?term={search string}'$ curl --location --request POST '127.0.0.1:8000/add' --header 'Authorization: token {token}' --form 'location={name}' --form 'popularity={value}'$ curl --location --request POST '127.0.0.1:8000/delete' --header 'Authorization: token {token}' --form 'location={name}'$ curl --location --request POST '127.0.0.1:8000/modify' --header 'Authorization: token {token}' --form 'location={name}' --form 'popularity={value}'