itsvinayak / frejun-interview-project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

frejun-interview-project

Task to be completed

  • Create Signup, Login and Logout APIs (No frontend needed)
  • Create an upload API using which you can upload a CSV file and create Candidate (Name, Phone number) objects in the database Note: These candidates should be created with respect to the user.
  • Create an API to obtain these candidates with pagination as 10.

Installation

creating virtualenv and install requirement

 python3 -m venv env 
 pip install -r requirements.txt 

Running celery ( make sure rabbitmq/redis is working )

 celery -A config worker -l info

APIs

Register api

curl -X POST \
  'http://127.0.0.1:8000/api/user/register/' \
  -H 'Accept: */*' \
  -H 'User-Agent: Thunder Client (https://www.thunderclient.io)' \
  --form 'username="developer"' \
  --form 'email="ddd@gmail.com"' \
  --form 'password="vinayak1@"' \
  --form 'password2="vinayak1@"'

Screenshot from 2021-07-30 02-45-54

Login api

curl -X POST \
  'http://127.0.0.1:8000/api/user/login/' \
  -H 'Accept: */*' \
  -H 'User-Agent: Thunder Client (https://www.thunderclient.io)' \
  -H 'Authorization: Token 316e7a138d986b54acce3e4dfb64e5f61f254cec' \
  --form 'username="vinayak"' \
  --form 'password="vinayak"'

Screenshot from 2021-07-30 02-46-21

upload csv file (gives error responce if any other formant)

make sure you have celery running

curl -X PUT \
  'http://127.0.0.1:8000/api/candidate/upload/' \
  -H 'Accept: */*' \
  -H 'User-Agent: Thunder Client (https://www.thunderclient.io)' \
  -H 'Authorization: Token 74c07c1660babb615c5ad87a752c3dd7c6a9adef' \
  -F 'file=@/home/vinayak/config/example_v.csv'

Screenshot from 2021-07-30 02-47-37

Show candidate api with pagination 10

 curl -X GET \
  'http://127.0.0.1:8000/api/candidate/show/' \
  -H 'Accept: */*' \
  -H 'User-Agent: Thunder Client (https://www.thunderclient.io)' \
  -H 'Authorization: Token 74c07c1660babb615c5ad87a752c3dd7c6a9adef'

Screenshot from 2021-07-30 02-47-05

for speeding up and to optimize the creation of object in database with minimum hits. I have used .bulk_create(obj) method which hits database only once

code used :

 with transaction.atomic():
        Candidate.objects.bulk_create(obj)

About


Languages

Language:Python 100.0%