Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Reward system for the app Disease Tracker & web application.

Description

The project includes a system of rewards for activity when adding data to the application database: first, the user needs to add data from his electronic wallet, then for each added test card, the user will receive a reward to the balance of his wallet.

Functionality

  • Registration and Authentication (JWT+Djoser). Users register using a username and password. The registered user receives a JWT token. It is used for further authentication. Token and user management is implemented using the Djoser library. Further API functionality is available only for authenticated users.
  • Adding wallet data. The user adds his wallet data to the application database. One user can add only one wallet. When trying to add a second wallet, the user will receive an error message.
  • Adding test cards. The user can add their test cards to the application database. The number of test cards for the user is unlimited.
  • Reward. When adding test cards, the user will receive a reward to the balance of his wallet for each added card.
  • Permission. The user can view information about his wallet and the list of added test cards via a GET request. The user cannot view wallet data or test card data from other users. The user cannot add, update, or delete data from wallets and test cards of other users.

Technologies

  • Python 3.9
  • Django 4.2.8
  • Django Rest Framework 3.14.0
  • djangorestframework-simplejwt 4.7.2
  • djoser 2.1.0
  • drf-spectacular 0.27.0

Project launch

Clone the repository and navigate to it in the command line:

git clone https://github.com/DmitryOstrovskiy/API_Reward && cd API_Reward

Install the virtual environment, activate it and install dependencies:

python -m venv venv && Windows: ```source venv\scripts\activate```; Linux/Mac: ```sorce venv/bin/activate``` && pip install -r requirements.txt

Perform migrations:

python manage.py migrate

Create a superuser:

python manage.py createsuperuser

Start the server:

python manage.py runserver

The project is launched at:

Query examples

Registration of the user

POST: http://127.0.0.1:8000/auth/users/

Request example:

{
    "username": "newuser4",
    "password": "Changeme4!"
}

Response example:

{
    "email": "",
    "username": "newuser4",
    "id": 5
}

Getting a JWT token

POST: http://127.0.0.1:8000/auth/jwt/create/
Request example:

{
    "username": "newuser4",
    "password": "Changeme4!"
} 

Response example:

{
    "refresh": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoicmVmcmVzaCIsImV4cCI6MTcwMzc2OTc3MywianRpIjoiZDEwYTQ2NGE0ODg3NDhjYzlkYjQxZmJhNGRhNDU3ZTIiLCJ1c2VyX2lkIjo1fQ.fjB-bMNBGc2funKhLndge-1wEaQ4fSL_YaDZk6Nc49Q",
    "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNzAzNzY5NzczLCJqdGkiOiI0ODdiNjgyNWViNGM0OGY1OTA5NTc0MmNhYzllYzI1MCIsInVzZXJfaWQiOjV9.tALtVLcENL3_rIwpO2z0phk-3xICdornj8SH_dXAv-M"
}

Further functionality is available only to authenticated users. In Postman, you need to select the "Bearer Token" authorization type in the Authorization tab and specify the JWT token already there. You need to take an access token.

Adding wallet data

POST: http://127.0.0.1:8000/api/v1/wallet/ - In the Authorization tab, you need to pass an access token Request example:

{
    "wallet_address": "QAZWSXEDC1234567890qaz0",
    "private_key": "private_key3",
    "public_key": "public_key3",
    "mnemonic_phrase": "phrase3"
}

Response example:

{
    "id": 3,
    "wallet_address": "QAZWSXEDC1234567890qaz0",
    "wallet_balance": 0,
    "private_key": "private_key3",
    "public_key": "public_key3",
    "mnemonic_phrase": "phrase3",
    "user": 5
}

Adding test card data

POST: http://127.0.0.1:8000/api/v1/testcards/ - In the Authorization tab, you need to pass an access token Request example:

{
    "name": "tescard15",
    "parameter": "parameter15",
    "parameter_value": "parameter_value15"
}

Response example:

{
    "id": 17,
    "name": "tescard15",
    "parameter": "parameter15",
    "parameter_value": "parameter_value15",
    "pub_date": "2023-12-27T13:35:42.151752Z",
    "author": 5
}

Getting wallet data

GET: http://127.0.0.1:8000/api/v1/wallet/ - In the Authorization tab, you need to pass an access token

Response example:

[
    {
        "id": 1,
        "wallet_address": "QAZWSXEDC1234567890",
        "wallet_balance": 4,
        "private_key": "private_key1",
        "public_key": "public_key1",
        "mnemonic_phrase": "phrase1",
        "user": 2
    }
]

Getting testcdrds data

GET: http://127.0.0.1:8000/api/v1/testcsrds/ - In the Authorization tab, you need to pass an access token

Response example:

[
    {
        "id": 2,
        "name": "tescard2",
        "parameter": "parameter2",
        "parameter_value": "parameter_value2",
        "pub_date": "2023-12-26T14:50:43.888915Z",
        "author": 3
    },
    {
        "id": 3,
        "name": "tescard3put",
        "parameter": "parameter3put",
        "parameter_value": "parameter_value3put",
        "pub_date": "2023-12-26T15:11:13.629509Z",
        "author": 3
    },
    {
        "id": 16,
        "name": "tescard10",
        "parameter": "parameter10",
        "parameter_value": "parameter_value10",
        "pub_date": "2023-12-27T08:02:09.908519Z",
        "author": 3
    }
]

Author - Dmitry Ostrovsky

πŸ’« About Me:

πŸ”­ I am currently working on Django projects
πŸ‘― I’m looking to collaborate on
🀝 I’m looking for help with
🌱 I am currently learning how to work with FastAPI
πŸ’¬ Ask me about
⚑ Fun fact

🌐 Socials:

LinkedIn

πŸ’» Tech Stack:

Python HTML5 Markdown PowerShell Django DjangoREST FastAPI JWT NodeJS Nginx Postgres Redis SQLite Docker

πŸ“Š GitHub Stats:




About

API for the reward system application

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages