Test assignment for DimaTech Ltd.
Developed using the asynchronous Sanic framework and the SQLAlchemy ORM.
This project provides you a working sanic environment without requiring you to install Python/Sanic, a web server, and any other server software on your local machine. For this, it requires Docker and Docker Compose.
-
Install Docker and Docker-compose;
-
Clone this project and then cd to the project folder;
-
Create your own .env file by copying .env.example:
$ cp src/.env.default src/.env
-
Update the environment variables in the docker-compose.yml and .env files.
-
Build the images and run the containers:
$ docker-compose -f docker-compose.yml up -d --build
-
You've done! Main page is available on http://localhost, pgAdmin on http://localhost:2345 (login: admin@admin.com, password: postgres)
-
After finishing work, you can stop running containers:
$ docker-compose down
To use it, you must have a server and a domain configured
-
Create a nginx configuration file to handle ssl:
$ mkdir conf.d $ cp ./Docker/nginx/nginx.prod.conf ./conf.d/nginx.conf
-
Update the environment variables:
2.1. In the docker-compose.yml variable "CERTBOT_EMAIL"
2.2. In the conf.d/nginx.conf variable "server_name"
-
Build the images and run the containers:
$ docker-compose -f docker-compose.prod.yml up -d --build
-
You've done! Main page is available on https://your_web_site
To use the site, you have access to the main addresses:
/v1/api/products/ - for viewing and editing products
Required request fields for POST method
title: text
description: text
price: float
/v1/api/bills/ - to view and edit customer bills
Required request fields for POST method
user_id: int
bill_balance: float
/v1/api/transactions/ - to view and edit transactions
Required request fields for POST method
user_id: int
bill_id: int
amount: float
/v1/api/purchases/ - to view and edit purchases
Required request fields for POST method
product_id: int
user_id: int
bill_id: int
GET /v1/auth/users/ - for viewing users
POST /v1/auth/users/ - for creating users
Required request fields for POST method
username: text
password: text
PATCH /v1/auth/users/{id}/ - for editing users
Request fields
password: text
email: int
is_active: bool - to enable/disable the user
is_admin: bool - to enable/disable admin role
GET /v1/auth/activate/{token}/ - for activating users
POST /v1/auth/login/ - to create a jwt token
Required request fields for POST method
username: text
password: text
POST /v1/payment/webhook - for sending webhook of transactions
Required request fields for POST method
signature: text
transaction_id: int
user_id: int
bill_id: int
amount: float
host:2345/ - pgAdmin for interaction with the database tables (login: admin@admin.com, password: postgres)
Note: default users can view accounts, transactions and purchases associated with them. Administrators can view the data of all users
The initial administrator is assigned in the database, subsequent ones in the database or by changing the is_admin field of a certain user
This project is licensed under the MIT license.