rest-api

Django restful app for storing and sending feedback messages with task queue
git clone

For sending email you can use google smtp
To run project we need install Python, PostgreSQL and Redis for work with Celery.

sudo apt update
sudo apt install python3-pip python3-dev libpq-dev postgresql postgresql-contrib redis-server

After, we need create new database and user for postgres.

sudo -u postgres psql
postgres=# CREATE DATABASE django_db;
postgres=# CREATE USER django WITH PASSWORD 'password';
postgres=# ALTER ROLE django SET client_encoding TO 'utf8';
postgres=# ALTER ROLE django SET default_transaction_isolation TO 'read committed';
postgres=# ALTER ROLE django SET timezone TO 'UTC';
postgres=# GRANT ALL PRIVILEGES ON DATABASE django_db TO django;
postgres=# \q

We need install python virtual environment, requred libs and configure app settings:

sudo -H pip3 install --upgrade pip
sudo -H pip3 install virtualenv
cd ~/rest-api
python3 -m venv .venv
source /.venv/bin/activate
pip3 install -r requirements.txt

open ~/rest-api/settings/settings.py and edit this lines

SECRET_KEY = '' #input your secret key
EMAIL_HOST_USER = '' #input your gmail
EMAIL_HOST_PASSWORD = '' #input your gmail password
Next step apply migrations

python3 manage.py migrate

You can run tests to make sure the app is working

python3 manage.py test

And start redis to use celery

redis-server
celery worker -A settings

Finally run django

python3 manage.py runserver

API:
For get auth token used djoser
POST | api/v1/auth/token/login

{
"password": "string",
"username": "string"
}

When database entry created, celery will send email with feedback message.
If need attach files to message specify it pk or leave blank if there no files.
POST|api/v1/feedback

{
"full_name": "string",
"email": "user@example.com",
"message": "string",
"files_to_send": [
pk
]
}

For other CRUD actions, you need create user with superuser permissoins:

python3 manage.py createsuperuser
put auth token in header.

You can upload file it attach to a email message
POST|api/v1/upload

content type: multipart/form-data
name = 'uploaded_file' , file_name = 'filename.jpg'

Also you can use swagger /swagger/ or redoc /redoc/ to get more information about API