mirror of
https://github.com/dancojocaru2000/foxbank.git
synced 2025-02-22 23:39:36 +02:00
Added initial server database work
This commit is contained in:
parent
78c30e28d4
commit
188cca8c39
11 changed files with 155 additions and 4 deletions
2
server/.dockerignore
Normal file
2
server/.dockerignore
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
__pycache__/
|
||||||
|
data/
|
2
server/.gitignore
vendored
Normal file
2
server/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
__pycache__/
|
||||||
|
data/
|
4
server/.vscode/extensions.json
vendored
4
server/.vscode/extensions.json
vendored
|
@ -1,5 +1,3 @@
|
||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": []
|
||||||
"ms-python.python"
|
|
||||||
]
|
|
||||||
}
|
}
|
3
server/.vscode/settings.json
vendored
Normal file
3
server/.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"python.pythonPath": "/home/kbruen/.local/share/virtualenvs/server-4otskhbj/bin/python"
|
||||||
|
}
|
13
server/Dockerfile
Normal file
13
server/Dockerfile
Normal file
|
@ -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" ]
|
|
@ -5,6 +5,7 @@ name = "pypi"
|
||||||
|
|
||||||
[packages]
|
[packages]
|
||||||
flask = "*"
|
flask = "*"
|
||||||
|
gunicorn = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
|
|
||||||
|
|
18
server/Pipfile.lock
generated
18
server/Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"_meta": {
|
"_meta": {
|
||||||
"hash": {
|
"hash": {
|
||||||
"sha256": "295fa60b4ad3b19ec29744ec2dfafba79ad5ee9a0b9ff095ac626e3d3981f117"
|
"sha256": "8886b8a6c0d31987ddea5b9e25bd02f7891650c967351486fd3cf0fd4d16271e"
|
||||||
},
|
},
|
||||||
"pipfile-spec": 6,
|
"pipfile-spec": 6,
|
||||||
"requires": {
|
"requires": {
|
||||||
|
@ -32,6 +32,14 @@
|
||||||
"index": "pypi",
|
"index": "pypi",
|
||||||
"version": "==2.0.2"
|
"version": "==2.0.2"
|
||||||
},
|
},
|
||||||
|
"gunicorn": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:9dcc4547dbb1cb284accfb15ab5667a0e5d1881cc443e0677b4882a4067a807e",
|
||||||
|
"sha256:e0a968b5ba15f8a328fdfd7ab1fcb5af4470c28aaf7e55df02a99bc13138e6e8"
|
||||||
|
],
|
||||||
|
"index": "pypi",
|
||||||
|
"version": "==20.1.0"
|
||||||
|
},
|
||||||
"itsdangerous": {
|
"itsdangerous": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:5174094b9637652bdb841a3029700391451bd092ba3db90600dea710ba28e97c",
|
"sha256:5174094b9637652bdb841a3029700391451bd092ba3db90600dea710ba28e97c",
|
||||||
|
@ -123,6 +131,14 @@
|
||||||
"markers": "python_version >= '3.6'",
|
"markers": "python_version >= '3.6'",
|
||||||
"version": "==2.0.1"
|
"version": "==2.0.1"
|
||||||
},
|
},
|
||||||
|
"setuptools": {
|
||||||
|
"hashes": [
|
||||||
|
"sha256:b4c634615a0cf5b02cf83c7bedffc8da0ca439f00e79452699454da6fbd4153d",
|
||||||
|
"sha256:feb5ff19b354cde9efd2344ef6d5e79880ce4be643037641b49508bbb850d060"
|
||||||
|
],
|
||||||
|
"markers": "python_version >= '3.6'",
|
||||||
|
"version": "==59.4.0"
|
||||||
|
},
|
||||||
"werkzeug": {
|
"werkzeug": {
|
||||||
"hashes": [
|
"hashes": [
|
||||||
"sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f",
|
"sha256:63d3dc1cf60e7b7e35e97fa9861f7397283b75d765afcaefd993d6046899de8f",
|
||||||
|
|
36
server/db.py
Normal file
36
server/db.py
Normal file
|
@ -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()
|
9
server/docker-compose.yml
Normal file
9
server/docker-compose.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
version: '3.9'
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build: .
|
||||||
|
image: foxbank-server
|
||||||
|
ports:
|
||||||
|
- ${PORT:-5000}:5000
|
||||||
|
volumes:
|
||||||
|
- ./data:/app/data
|
61
server/init.sql
Normal file
61
server/init.sql
Normal file
|
@ -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)
|
||||||
|
);
|
10
server/server.py
Normal file
10
server/server.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
from flask import Flask
|
||||||
|
|
||||||
|
import db
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
db.init_app(app)
|
||||||
|
|
||||||
|
@app.get('/')
|
||||||
|
def root():
|
||||||
|
return 'Hello from FoxBank!'
|
Loading…
Add table
Reference in a new issue