Steps to set up the project.
- run " git clone https://github.com/ongraphpythondev/backend_test.git "
- move to the projet folder & create virtualenv using command "virtualenv venv"
- run "pip install -r requirements.txt".
- move to the project base dirctory
- run "python manage.py migrate"
- run django server "python manage.py runserver"
Now you have successfully run the server locally. You can test APIs using Postman or thunderclient
Unit Testing:
- You can run test using "python manage.py test" (don't need to run django server)
Assumptions:
- User can be seller or buyer both.
- User can publish the bonds, A uuid will be generated for each bond and linked to user(seller) who published the bond.
- Only authenticated user can access the all APIs.
- User can't see bonds publised by himself.
- User can't buy his own bond.
- User can't buy bond if some user buy the bond already.
Here is the list of all endpoints & their request body
-
POST -> http://127.0.0.1:8000/api/signup
json body:
{ "email":"vip@gmail.com", "password":"vip12345" }
Status: 200 OK
Response body:
{ "message": "user created" }
-
POST -> http://127.0.0.1:8000/api/login
json body:
{ "email":"vip@gmail.com", "password":"vip12345" }
Status: 200 OK
Response body:
{ "message": "logged in", "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" }
-
POST -> http://127.0.0.1:8000/api/publishbond
json body:
{ "name":"Bondtypeorname", "price":31, "number_of_bond": 3 }
Headers:
{ "Accept": "application/json", "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" }
Status: 200 OK
Response body:
{ "message": "bond published", "uuid": "3890427a-9662-438e-a447-1e653b9a10ac" }
-
GET -> http://127.0.0.1:8000/api/bondlist json body: None
Headers:
{ "Accept": "application/json", "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" }
Status: 200 OK
Response body:
{ "bonds": [ { "id": "fbedc5e9-67df-47e1-9514-066341b27acc", "name": "Befdsffdfw", "price": "310.0000", "number_of_bond": 3, "seller_id": 1, "buyer_id": null }, { "id": "f78ea895-9289-449b-93c0-55c17550558a", "name": "Befdsffdsffdfw", "price": "310.0000", "number_of_bond": 3, "seller_id": 2, "buyer_id": 3 } ] }
-
GET -> http://127.0.0.1:8000/api/listinusdollar
json body: None
Headers:
{ "Accept": "application/json", "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" }
Status: 200 OK
Response body:
{ "bonds": [ { "id": "fbedc5e9-67df-47e1-9514-066341b27acc", "name": "Befdsffdfw", "price": 15.3766, "number_of_bond": 3, "seller_id": 1, "buyer_id": 3 }, { "id": "f78ea895-9289-449b-93c0-55c17550558a", "name": "Befdsffdsffdfw", "price": 15.3766, "number_of_bond": 3, "seller_id": 2, "buyer_id": 2 }, { "id": "3890427a-9662-438e-a447-1e653b9a10ac", "name": "Befdsffdfw", "price": 15.3766, "number_of_bond": 3, "seller_id": 3, "buyer_id": null } ]
}
-
POST -> http://127.0.0.1:8000/api/buybound
json body:
{ "id":"fbedc5e9-67df-47e1-9514-066341b27acc" #uuid of bond }
Headers:
{ "Accept": "application/json", "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InZpcEBnbWFpbC5jb20iLCJwYXNzd29yZCI6InZpcDEyMzQ1IiwidXVpZCI6IjIwOTZlZjMwLWVjMTEtNDNhNi05NjI5LWE1MmJlN2RmMmFhNyIsImV4cCI6MTY0OTQzMDgzMn0.qPNLMm6ashErMJmmmNyR74EFn_ixjvDxQ7bx2VPIOiE" }
Status: 200 OK
Response body:
{ 'message':'bond bought successfully' }