Kenneth Bruen
3 years ago
11 changed files with 155 additions and 4 deletions
@ -1,5 +1,3 @@ |
|||||||
{ |
{ |
||||||
"recommendations": [ |
"recommendations": [] |
||||||
"ms-python.python" |
|
||||||
] |
|
||||||
} |
} |
@ -0,0 +1,3 @@ |
|||||||
|
{ |
||||||
|
"python.pythonPath": "/home/kbruen/.local/share/virtualenvs/server-4otskhbj/bin/python" |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
FROM python:3.10-slim |
||||||
|
|
||||||
|
RUN pip3 install pipenv |
||||||
|
|
||||||
|
WORKDIR /app |
||||||
|
|
||||||
|
COPY Pipfile Pipfile.lock ./ |
||||||
|
RUN pipenv install |
||||||
|
|
||||||
|
COPY . . |
||||||
|
|
||||||
|
EXPOSE 5000 |
||||||
|
CMD [ "pipenv", "run", "gunicorn", "-b", "0.0.0.0:5000", "server:app" ] |
@ -0,0 +1,36 @@ |
|||||||
|
import sqlite3 |
||||||
|
|
||||||
|
from flask import current_app, g |
||||||
|
|
||||||
|
DB_FILE = './data/db.sqlite' |
||||||
|
|
||||||
|
def get(): |
||||||
|
if 'db' not in g: |
||||||
|
g.db = sqlite3.connect( |
||||||
|
DB_FILE, |
||||||
|
detect_types=sqlite3.PARSE_DECLTYPES, |
||||||
|
) |
||||||
|
g.db.row_factory = sqlite3.Row |
||||||
|
|
||||||
|
return g.db |
||||||
|
|
||||||
|
def close(e=None): |
||||||
|
db = g.pop('db', None) |
||||||
|
|
||||||
|
if db: |
||||||
|
db.close() |
||||||
|
|
||||||
|
def init(): |
||||||
|
db = get() |
||||||
|
|
||||||
|
with current_app.open_resource('init.sql') as f: |
||||||
|
db.executescript(f.read().decode('utf8')) |
||||||
|
db.commit() |
||||||
|
|
||||||
|
def init_app(app): |
||||||
|
app.teardown_appcontext(close) |
||||||
|
|
||||||
|
import os.path |
||||||
|
if not os.path.exists(DB_FILE): |
||||||
|
with app.app_context(): |
||||||
|
init() |
@ -0,0 +1,9 @@ |
|||||||
|
version: '3.9' |
||||||
|
services: |
||||||
|
web: |
||||||
|
build: . |
||||||
|
image: foxbank-server |
||||||
|
ports: |
||||||
|
- ${PORT:-5000}:5000 |
||||||
|
volumes: |
||||||
|
- ./data:/app/data |
@ -0,0 +1,61 @@ |
|||||||
|
drop table if exists users; |
||||||
|
drop table if exists accounts; |
||||||
|
drop table if exists users_accounts; |
||||||
|
drop table if exists transactions; |
||||||
|
drop table if exists accounts_transactions; |
||||||
|
drop table if exists notifications; |
||||||
|
drop table if exists users_notifications; |
||||||
|
|
||||||
|
create table users ( |
||||||
|
id integer primary key autoincrement, |
||||||
|
username text unique not null, |
||||||
|
email text unique not null, |
||||||
|
otp text not null, |
||||||
|
fullname text not null |
||||||
|
); |
||||||
|
|
||||||
|
create table accounts ( |
||||||
|
id integer primary key autoincrement, |
||||||
|
iban text unique not null, -- RO16 FOXB 0000 0000 0000 0000 |
||||||
|
currency text not null, -- EUR, RON, USD, ? |
||||||
|
account_type text not null, -- checking, savings, ? |
||||||
|
custom_name text -- 'Car Savings'; name set by user |
||||||
|
); |
||||||
|
|
||||||
|
create table users_accounts ( |
||||||
|
user_id integer not null, -- one user can have multiple accounts |
||||||
|
account_id integer UNIQUE not null, -- one account can only have one user |
||||||
|
foreign key (user_id) references users (id), |
||||||
|
foreign key (account_id) references accounts (id) |
||||||
|
); |
||||||
|
|
||||||
|
create table transactions ( |
||||||
|
id integer primary key autoincrement, |
||||||
|
datetime text not null, |
||||||
|
other_party text not null, -- JSON data describing sender/recipient/etc |
||||||
|
-- depending on transaction type |
||||||
|
status text not null, -- processed, failed, reverted, pending, etc |
||||||
|
type text not null, -- send_transfer, receive_transfer, card_payment, fee, ... |
||||||
|
extra text -- depending on type, JSON data describing extra info |
||||||
|
); |
||||||
|
|
||||||
|
create table accounts_transactions ( |
||||||
|
account_id integer not null, |
||||||
|
transaction_id integer UNIQUE not null, |
||||||
|
foreign key (account_id) references accounts (id), |
||||||
|
foreign key (transaction_id) references transactions (id) |
||||||
|
); |
||||||
|
|
||||||
|
create table notifications ( |
||||||
|
id integer primary key autoincrement, |
||||||
|
body text not null, |
||||||
|
datetime text not null, |
||||||
|
read integer not null |
||||||
|
); |
||||||
|
|
||||||
|
create table users_notifications ( |
||||||
|
user_id integer not null, |
||||||
|
notification_id integer UNIQUE not null, |
||||||
|
foreign key (user_id) references users (id), |
||||||
|
foreign key (notification_id) references notifications (id) |
||||||
|
); |
Loading…
Reference in new issue