NOTE : Please check these Published API Docs to get examples and information of all test cases of the API endpoints.
- Django
- Django REST framework
- PostgreSQL
- Docker
- Docker Compose
- backend : The API endpoints folder with all settings and configuration.
- Dockerfile : Dockerfile to build the image for the backend APIs.
- requirements.txt : Requirements file with all the necessary dependencies required to run the project.
- docker-compose.yml : YAML file configure the back end, and the database service.
- user : App for user authentication and user roles and permissions.
- loan : App for the loan management of the users.
- User test cases present at tests
- Loan test cases present at tests
Pre-requites:
- python3.7 or greater
- docker version 20.10.x
- docker-compose version 1.29.x
Steps:
- Navigate to the directory with Dockerfile and use the following command:
docker build --force-rm -t backend:latest .
- Check your local docker image repository to see if the image has been built. Use command:
docker images
- Navigate to the folder with docker-compose.yml.
- To run migrations and set up the database, use commands:
docker-compose run --rm apis python manage.py makemigrations user
docker-compose run --rm apis python manage.py makemigrations loan
docker-compose run --rm apis python manage.py migrate
- To start the development server, use command:
docker-compose up --remove-orphans
- To shut the development serve, use command:
docker-compose down --remove-orphans
7. IMPORTANT: To test the backend with test cases, use command:
docker-compose run --rm apis python manage.py test
- Create the first admin user of the system using command:
docker-compose run --rm apis python manage.py createsuperuser
- There are 3 roles in the system - Customer, Agent, Admin.
- Admins are the highest role available in the system and they can access the admin panel at http://127.0.0.1:8000/admin/ to view all data.
- PBKDF2 algorithm with a SHA256 hash is used for hashing the password before storing it in the database.
- permissions.py is used to set permissions of the user.
- JWT is used to perform token authentication and the token is only valid for 2 hours after it's creation. This is to increase security of the system.
- After 2 hours, a new token needs to be requested from the server.
- Every API call is protected by permissions and authentication to ensure maximum safety.
- History for "double safety" is being logged at every change made to a loan object. This can help us to rollback in extreme cases. Here is an example,
- Filter by loan type is present.
- Indian Standard Timezone is considered in the system and date handling is done accordingly.
- Base URL : http:127.0.0.1:8000/api
- User APIs:
- Signup: /user/signup/
- This endpoint can be used to sign up a user(customer or agent).
- Cannot signup if user already exists.
- Tokens have a validity of 2 hours only after which re-login is required.
- A user token is generated on successful registration.
- POST request has to be sent to this endpoint.
- Create Admin: /user/create-admin/
- This endpoint can be used by ADMINS ONLY to make more admin users.
- Authorization of admin level required to access this endpoint.
- POST request has to be sent to this endpoint.
- Login : /user/login/
- This endpoint can be used to log in by admin, agent or customer.
- Cannot log in agent if it is not approved by the admin.
- Admin and Customer can login using correct credentials directly.
- A user token is generated on successful login.
- Tokens have a validity of 2 hours only after which re-login is required.
- POST request has to be sent to this endpoint.
- Profile : /user/profile/
- This endpoint can display the user information depending on the authorization token present in the header.
- Authorization is required to access this endpoint.
- GET request has to be sent to this endpoint.
- List Users(Agent) : /user/list-agent/
- This endpoint can be used by AGENTS OR ADMINS to list the customers present in the system.
- Customer role cannot access this endpoint.
- Authorization required to access this endpoint.
- GET request has to be sent to this endpoint.
- List Users(Admin) : /user/list-approvals/
- This endpoint can be used by ADMINS only to list the customers and agents present in the system.
- Customer and Agent role cannot access this endpoint.
- Authorization required to access this endpoint.
- GET request has to be sent to this endpoint.
- Approve or Delete and Agent : /user/approve-delete/int:pk/
- This endpoint can be used by ADMINS only to list approve an agent to the system or delete one.
- Customer and Agent role cannot access this endpoint.
- Authorization required to access this endpoint.
- PUT request with int:pk i.e. agent ID as a URL parameter with is_approved status can be used to approve or reject an agent.
- DELETE request with int:pk i.e. agent ID as a URL parameter can be used to delete an agent.
- Signup: /user/signup/
- Loan APIs:
- Request Loan by Agent for Customer : /loan/customer-loan/
- This endpoint is for the agent to request a loan to the admin on behalf of a customer.
- Only Agent role can access this endpoint.
- Authorization required to access this endpoint.
- POST request has to be sent to this endpoint.
- Approve or Reject a loan by admin : /loan/approve-reject-loan/int:pk/
- This endpoint is for the ADMIN users only to accept or reject a loan request.
- Customer and Agent role cannot access this endpoint.
- Authorization required to access this endpoint.
- PUT request with int:pk i.e. loan ID as a URL parameter and status in the body can be used to approve or reject a loan.
- Edit Loan by agent : /loan/edit-loan/int:pk/
- This endpoint is for the AGENT role only to edit loan details for a user.
- Authorization required to access this endpoint.
- PUT request with int:pk i.e. loan ID as a URL parameter and new loan details in the body can be used to edit a loan.
- If loan is already approved, then edit is not allowed.
- List Loans of all customers to Admins and Agents : /loan/list-loans-admin-agent/
- This endpoint can be used by agents and admin users to list all loans in the system.
- Customer role cannot access this endpoint.
- Authorization required to access this endpoint.
- GET request has to be sent to this endpoint.
- Filters available:
- status?=NEW
- status?=APPROVED
- status?=REJECTED
- For example:
- For only one of the filters use: http://localhost:8000/api/loan/list-loans-admin-agent?status=APPROVED
- List Loans of a particular Customer : /loan/list-loans-customer/
- This endpoint can be used by customers to list their loans in the system.
- Authorization required to access this endpoint.
- GET request has to be sent to this endpoint.
- Filters available:
- status?=NEW
- status?=APPROVED
- status?=REJECTED
- For example:
- For only one of the filters use: http://localhost:8000/api/loan/list-loans-admin-agent?status=APPROVED
- Request Loan by Agent for Customer : /loan/customer-loan/