diff --git a/.gitignore b/.gitignore index d4c539f..a41af78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ +# Bank Management System files flask_session/ -application/__pycache__/ -application/session_data.json -server/bank.db -server/test_database.db -server/log.txt +session_data.json +bank.db +log.txt # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/database/class_account.py b/database/class_account.py new file mode 100644 index 0000000..f8ee9a4 --- /dev/null +++ b/database/class_account.py @@ -0,0 +1,43 @@ +# Lucas Mathews - Fontys Student ID: 5023572 +# Banking System Account Class + +from sqlalchemy import ForeignKey, Column, String, Integer, Boolean +from sqlalchemy.orm import relationship + +from class_base import Base + +class Account(Base): + __tablename__ = 'accounts' + account_id = Column("account_id", String, primary_key=True) + client_id = Column(String, ForeignKey('clients.client_id')) + description = Column("description", String) + open_timestamp = Column("open_timestamp", String) + account_type = Column("account_type", String) + balance = Column("balance", Integer) + enabled = Column("enabled", Boolean) + notes = Column("notes", String) + transactions = relationship("Transaction", foreign_keys='Transaction.account_id', backref="account") + + def __init__(self, account_id, client_id, description, open_timestamp, account_type, balance, enabled, notes, transactions): + """Initialises the account object.""" + self.account_id = account_id + self.client_id = client_id + self.description = description + self.open_timestamp = open_timestamp + self.account_type = account_type + self.balance = balance + self.enabled = enabled + self.notes = notes + self.transactions = transactions if transactions is not None else [] + + def to_dict(self): + """Returns the account as a dictionary.""" + return { + "account_id": self.account_id, + "client_id": self.client_id, + "description": self.description, + "open_timestamp": self.open_timestamp, + "account_type": self.account_type, + "balance": self.balance, + "notes": self.notes + } \ No newline at end of file diff --git a/database/class_base.py b/database/class_base.py new file mode 100644 index 0000000..0439352 --- /dev/null +++ b/database/class_base.py @@ -0,0 +1,6 @@ +# Lucas Mathews - Fontys Student ID: 5023572 +# Banking System Base Class + +from sqlalchemy.orm import declarative_base + +Base = declarative_base() \ No newline at end of file diff --git a/database/class_client.py b/database/class_client.py new file mode 100644 index 0000000..8c7da78 --- /dev/null +++ b/database/class_client.py @@ -0,0 +1,50 @@ +# Lucas Mathews - Fontys Student ID: 5023572 +# Banking System Client Class + +from sqlalchemy import Column, String, Boolean +from sqlalchemy.orm import relationship + +from class_base import Base + +class Client(Base): + __tablename__ = 'clients' + client_id = Column("client_id", String, primary_key=True) + name = Column("name", String) + birthdate = Column("birthdate", String) + opening_timestamp = Column("opening_timestamp", String) + address = Column("address", String) + phone_number = Column("phone_number", String) + email = Column("email", String) + hash = Column("hash", String) + notes = Column("notes", String) + enabled = Column("enabled", Boolean) + administrator = Column("administrator", Boolean) + accounts = relationship("Account", backref="client") + + def __init__(self, client_id, name, birthdate, opening_timestamp, address, phone_number, email, hash, notes, enabled, administrator, accounts): + """Initialises the client object.""" + self.client_id = client_id + self.name = name + self.birthdate = birthdate + self.opening_timestamp = opening_timestamp + self.address = address + self.phone_number = phone_number + self.email = email + self.hash = hash + self.notes = notes + self.enabled = enabled + self.administrator = administrator + self.accounts = accounts if accounts is not None else [] + + def to_dict(self): + """Returns the client as a dictionary.""" + return { + "client_id": self.client_id, + "name": self.name, + "birthdate": self.birthdate, + "opening_timestamp": self.opening_timestamp, + "address": self.address, + "phone_number": self.phone_number, + "email": self.email, + } + \ No newline at end of file diff --git a/database/class_transaction.py b/database/class_transaction.py new file mode 100644 index 0000000..eddc3fa --- /dev/null +++ b/database/class_transaction.py @@ -0,0 +1,38 @@ +# Lucas Mathews - Fontys Student ID: 5023572 +# Banking System Transaction Class + +from sqlalchemy import Column, String, Integer, ForeignKey + +from class_base import Base + +class Transaction(Base): + __tablename__ = 'transactions' + transaction_id = Column("transaction_id", String, primary_key=True) + transaction_type = Column("transaction_type", String) + amount = Column("amount", Integer) + timestamp = Column("timestamp", String) + description = Column("description", String) + account_id = Column(String, ForeignKey('accounts.account_id')) + recipient_account_id = Column(String, ForeignKey('accounts.account_id')) + + def __init__(self, transaction_id, transaction_type, amount, timestamp, description, account_id, recipient_account_id = None): + """Initialises the Transaction object.""" + self.transaction_id = transaction_id + self.transaction_type = transaction_type + self.amount = amount + self.timestamp = timestamp + self.description = description + self.account_id = account_id + self.recipient_account_id = recipient_account_id + + def to_dict(self): + """Converts the Transaction object to a dictionary.""" + return { + "transaction_id": self.transaction_id, + "transaction_type": self.transaction_type, + "amount": self.amount, + "timestamp": self.timestamp, + "description": self.description, + "account_id": self.account_id, + "recipient_account_id": self.recipient_account_id + } \ No newline at end of file diff --git a/database/config.py b/database/config.py new file mode 100644 index 0000000..922ebe5 --- /dev/null +++ b/database/config.py @@ -0,0 +1,7 @@ +# Lucas Mathews - Fontys Student ID: 5023572 +# Banking System Config Parser + +import configparser + +CONFIG = configparser.ConfigParser() +CONFIG.read("database.ini") diff --git a/database/database.ini b/database/database.ini new file mode 100644 index 0000000..8e7fedf --- /dev/null +++ b/database/database.ini @@ -0,0 +1,5 @@ +[database] +name=bank.db + +[server] +url=http://0.0.0.0:80 \ No newline at end of file diff --git a/test_database_generator.py b/database/test_database_generator.py similarity index 99% rename from test_database_generator.py rename to database/test_database_generator.py index 0f29094..4b0a4f3 100644 --- a/test_database_generator.py +++ b/database/test_database_generator.py @@ -5,7 +5,7 @@ ADMIN_EMAIL = "lmath56@hotmail.com" from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -from class_base import Base +from server.class_base import Base from class_account import Account from class_client import Client from class_transaction import Transaction