Assignment for Backend Dev. position at Data Peace AI Technologies.
- Flask
- Flask-sqlAlchemy
- MySQL
- json, (demo data from http://demo9197058.mockable.io/users)
- Checkout https://github.com/namanchikara/heroku-datapeace-assignment
- I've hosted it on heroku, you can checkout https://datapeace-assignment.herokuapp.com/api/users
- I have NOT tested it and hence I don't recommend it for use; However all end points seems to be working in it as well and codebase is much more elegant
- Test 11 in
test.py
seems to be failing forheroku
version, That's why I would recommend you to checkout below given solution whoose db ismySQL
rather thanpostgre
- Both of the solutions are using
SQLAlchemy ORM
.
- Install
python 3
andgit
- Install
mysql-client
andmysql-server
- In terminal run
sudo mysql -e "use mysql; update user set authentication_string=PASSWORD('YOUR-PASSWORD-HERE') where User='root'; update user set plugin='mysql_native_password';FLUSH PRIVILEGES;create database datapeace; use datapeace;"
replaceYOUR-PASSWORD-HERE
with your desiredmysql
password - In last step we set password for mySQL AND created a new database namded
datapeace
<- on which db operations will be performed in this application. - Run
sudo mysql_upgrade -u root --password=YOUR-PASSWORD-HERE & sudo service mysql restart
- Clone this repo by running command
git clone https://github.com/namanchikara/datapeace-assignment.git
- Change directory to folder using
cd datapeace-assignment
- In case you want to use virtualenv, then you can do that too, make sure
virtualenv
is installed and then runvirtualenv venv -p python3
now to activate this virtual environment runsource venv/bin/activate
- Run command
pip install -r requirements.txt
- Open
run_app.py
and changepassword
to your mysql password you set in previous steps - Now to run the application run command
python run_app.py
- Server would now be running on
localhost
i.e127.0.0.1
- To run tests, run command
python test.py
- As this was a backend project, no GUI is present(Sorry), However you can use
postman
https://www.getpostman.com/ to send requests and receive response objects. - I've covered most of the endpoints in
test.py
file
-
/api/test/multipleUsers
-POST
- To add multiple users- Post request must send data in
json
format to populate db - Response with HTTP status code
201
on success{}
- Post request must send data in
-
/api/test/multipleUsers
-DELETE
- To delete all users in db -
/api/users
-GET
- To list the users.- Response with HTTP status code
200
on success. - Also, supports some query parameters:-
page
- a number for paginationlimit
- no. of items to be returned, default limit is 5name
- search user by name as a substring in First Name or Last Name (Note, use substring matching algorithm/pattern to match the name)Sort
- name of attribute, the items to be sorted. By default it returns items in ascending order if this parameter exist, and if the value of parameter is prefixed with โ-โ character, then it should return items in descending order.- Sample query endpoint:-
/api/users?page=1&limit=10&name=James&sort=-age
. This endpoint should return list of 10 users whose first name or last name contains substring given name and sort the users by age in descending order of page 1.
- Response with HTTP status code
-
/api/users
-POST
- To create a new user- Request Payload should be like in json format :-
- Response with HTTP status code
201
on success and{}
- This endpoint will create a new user inside the database
-
/api/users/{id}
-GET
- To get the details of a user- Here
{id}
will be the id of the user in path parameter - Response with HTTP status code
200
on success - Sample query looks like:-
/api/users/1
ofGET
type
- Here
-
/api/users/{id}
-PUT
- To update the details of a user- Here
{id}
will be the id of the user in path parameter - Request Payload should be like in
json
format for updating first name, last name and age:- - Response with HTTP status code
200
on success and{}
- Here
-
/api/users/{id}
-DELETE
- To delete the user- Here {id} will be the id of the user in path parameter
- Response with HTTP status code
200
on success{}
Build is currently passing on travis, for futher information regarding build or debugging installation process visit https://travis-ci.com/namanchikara/datapeace-assignment