Code Monkey home page Code Monkey logo

drf-referral's Introduction

DRF Referral System

Django Referral System is a Django-based application that serves as a template for building referral systems. It utilizes Django Rest Framework for creating RESTful APIs.

Tech Stack

  • Python
  • Django
  • Django Rest Framework
  • DRF Spectacular (for automatic documentation)
  • PostgreSQL

Description

This app provides a simple foundation for implementing a referral system. It includes a custom user model with authentication.

Installation

  1. Clone repo
git clone https://github.com/Asadhimself/drf-referral.git
  1. Install dependecies
pip install poetry
poetry install
  1. Rename .env.example to .env and set up your environment dependencies

  2. Run migrations

python manage.py makemigrations
python manage.py migrate
  1. Run the app
python manage.py runserver

Usage

localhost:8000/api/docs In this page (it's also home page) you can see automatically generated SwaggerUI docs.

Request

POST /api/login/

curl -d 'phone_number=+998901234567' http://localhost:8000/api/login/

Response:

{
  'phone_number': '+998901234567',
  'otp': '1234',
}

When you get OTP you can use it only once. After you getting Auth token OTP become useless.

You can get auth token by sending second request:

curl -X POST \
-H "Content-Type: application/json" \
-d '{"phone_number": "+998901234567", "otp": "1234"}' \
http://localhost:800/api/login/

Response:

{
	'url_account': '/api/account/',
	'token': 'some-auth-token'
}

Get Account

In order to authenticate you need to puth it into headers like shown in example:

Authorization: Token

Request

GET /api/account/

curl -H 'Authorization: Token some-auth-token' http://localhost:8000/api/account/

Response

{
	"url_account":"/api/account/",
	"phone_number":"+998901234567",
	"username":"+998901234567",
	"email":"",
	"first_name":"",
	"last_name":"",
	"last_login":"2022-03-30T04:59:02.718663+03:00",
	"date_joined":"2022-03-30T04:59:02.613466+03:00",
	"invite":null,
	"user_invite":{
		"pk":2,
		"key":"some-invite-key",
		"account_set":[]
	}
}

Change "username", "email", "first_name", "last_name"

Request

PUT /api/account/

curl -H 'Authorization: Token some-auth-token' -d 'username=Username' -X PUT http://localhost:8000/api/account/

Response

{
	"phone_number":"+998901234567",
	"username":"Username",
	"email":"",
	"first_name":"",
	"last_name":"",
	"last_login":"2024-04-26T03:37:02.5332455+05:00",
	"date_joined":"2024-04-26T03:37:02.5332455+05:00",
	"invite":null,
	"user_invite":{
		"pk":2,
		"key":"some-auth-key",
		"account_set":[]
	}
}

Add "invite" (Added once, cannot be changed later)

Request

PUT /api/account/

curl -H 'Authorization: Token some-auth-token' -d 'invite=user-invite-key' -X PUT http://localhost:8000/api/account/

Response

{
	"phone_number":"+998901234567",
	"username":"Username",
	"email":"",
	"first_name":"",
	"last_name":"",
	"last_login":"2022-03-30T04:59:02.718663+03:00",
	"date_joined":"2022-03-30T04:59:02.613466+03:00",
	"invite":"some-invite-key",
	"user_invite":{
		"pk":2,
		"key":"user-invite-key",
		"account_set":[]
	}
}

Disclaimer

This project served as a technical exercise for job application, but the employer ceased communication. The technical exercise details can be found here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.