First Code Commit

This commit is contained in:
Lucas Mathews
2024-05-17 10:48:19 +02:00
parent eeb1468453
commit 745ed14c56
39 changed files with 2227 additions and 0 deletions

686
Old/api.yml Normal file
View File

@@ -0,0 +1,686 @@
openapi: 3.0.3
info:
title: Banking System - OpenAPI 3.0
description: |-
This is the banking system API for the programming project.
contact:
email: 522499@student.fontys.nl
version: 1.0.11
servers:
- url: /
tags:
- name: accounts
description: Everything about your Accounts
- name: user
description: Operations about user
paths:
/Accounts:
put:
tags:
- accounts
summary: Update an existing account
description: Update an existing account by Id
operationId: updateAccount
requestBody:
description: Update an existing bank account
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
application/xml:
schema:
$ref: '#/components/schemas/Account'
text/html:
schema:
$ref: '#/components/schemas/Account'
required: true
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
application/xml:
schema:
$ref: '#/components/schemas/Account'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'422':
description: Validation exception
security:
- petstore_auth:
- write:pets
- read:pets
post:
tags:
- accounts
summary: Add a new pet to the store
description: Add a new pet to the store
operationId: addPet
requestBody:
description: Create a new pet in the store
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
application/xml:
schema:
$ref: '#/components/schemas/Account'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Account'
required: true
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
application/xml:
schema:
$ref: '#/components/schemas/Account'
'400':
description: Invalid input
'422':
description: Validation exception
security:
- petstore_auth:
- write:pets
- read:pets
/pet/findByStatus:
get:
tags:
- accounts
summary: Finds Pets by status
description: Multiple status values can be provided with comma separated strings
operationId: findPetsByStatus
parameters:
- name: status
in: query
description: Status values that need to be considered for filter
required: false
explode: true
schema:
type: string
default: available
enum:
- available
- pending
- sold
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Account'
application/xml:
schema:
type: array
items:
$ref: '#/components/schemas/Account'
'400':
description: Invalid status value
security:
- petstore_auth:
- write:pets
- read:pets
/pet/findByTags:
get:
tags:
- accounts
summary: Finds Pets by tags
description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
operationId: findPetsByTags
parameters:
- name: tags
in: query
description: Tags to filter by
required: false
explode: true
schema:
type: array
items:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Account'
application/xml:
schema:
type: array
items:
$ref: '#/components/schemas/Account'
'400':
description: Invalid tag value
security:
- petstore_auth:
- write:pets
- read:pets
/pet/{petId}:
get:
tags:
- accounts
summary: Find pet by ID
description: Returns a single pet
operationId: getPetById
parameters:
- name: petId
in: path
description: ID of pet to return
required: true
schema:
type: integer
format: int64
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
application/xml:
schema:
$ref: '#/components/schemas/Account'
'400':
description: Invalid ID supplied
'404':
description: Pet not found
security:
- api_key: []
- petstore_auth:
- write:pets
- read:pets
post:
tags:
- accounts
summary: Updates a pet in the store with form data
description: ''
operationId: updatePetWithForm
parameters:
- name: petId
in: path
description: ID of pet that needs to be updated
required: true
schema:
type: integer
format: int64
- name: name
in: query
description: Name of pet that needs to be updated
schema:
type: string
- name: status
in: query
description: Status of pet that needs to be updated
schema:
type: string
responses:
'400':
description: Invalid input
security:
- petstore_auth:
- write:pets
- read:pets
delete:
tags:
- accounts
summary: Deletes a pet
description: delete a pet
operationId: deletePet
parameters:
- name: api_key
in: header
description: ''
required: false
schema:
type: string
- name: petId
in: path
description: Pet id to delete
required: true
schema:
type: integer
format: int64
responses:
'400':
description: Invalid pet value
security:
- petstore_auth:
- write:pets
- read:pets
/pet/{petId}/uploadImage:
post:
tags:
- accounts
summary: uploads an image
description: ''
operationId: uploadFile
parameters:
- name: petId
in: path
description: ID of pet to update
required: true
schema:
type: integer
format: int64
- name: additionalMetadata
in: query
description: Additional Metadata
required: false
schema:
type: string
requestBody:
content:
application/octet-stream:
schema:
type: string
format: binary
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
security:
- petstore_auth:
- write:pets
- read:pets
/user:
post:
tags:
- user
summary: Create user
description: This can only be done by the logged in user.
operationId: createUser
requestBody:
description: Created user object
content:
application/json:
schema:
$ref: '#/components/schemas/User'
application/xml:
schema:
$ref: '#/components/schemas/User'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/User'
responses:
default:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/User'
application/xml:
schema:
$ref: '#/components/schemas/User'
/user/createWithList:
post:
tags:
- user
summary: Creates list of users with given input array
description: Creates list of users with given input array
operationId: createUsersWithListInput
requestBody:
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/User'
application/xml:
schema:
$ref: '#/components/schemas/User'
default:
description: successful operation
/user/login:
get:
tags:
- user
summary: Logs user into the system
description: ''
operationId: loginUser
parameters:
- name: username
in: query
description: The user name for login
required: false
schema:
type: string
- name: password
in: query
description: The password for login in clear text
required: false
schema:
type: string
responses:
'200':
description: successful operation
headers:
X-Rate-Limit:
description: calls per hour allowed by the user
schema:
type: integer
format: int32
X-Expires-After:
description: date in UTC when token expires
schema:
type: string
format: date-time
content:
application/xml:
schema:
type: string
application/json:
schema:
type: string
'400':
description: Invalid username/password supplied
/user/logout:
get:
tags:
- user
summary: Logs out current logged in user session
description: ''
operationId: logoutUser
parameters: []
responses:
default:
description: successful operation
/user/{username}:
get:
tags:
- user
summary: Get user by user name
description: ''
operationId: getUserByName
parameters:
- name: username
in: path
description: 'The name that needs to be fetched. Use user1 for testing. '
required: true
schema:
type: string
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/User'
application/xml:
schema:
$ref: '#/components/schemas/User'
'400':
description: Invalid username supplied
'404':
description: User not found
put:
tags:
- user
summary: Update user
description: This can only be done by the logged in user.
operationId: updateUser
parameters:
- name: username
in: path
description: name that need to be deleted
required: true
schema:
type: string
requestBody:
description: Update an existent user in the store
content:
application/json:
schema:
$ref: '#/components/schemas/User'
application/xml:
schema:
$ref: '#/components/schemas/User'
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/User'
responses:
default:
description: successful operation
delete:
tags:
- user
summary: Delete user
description: This can only be done by the logged in user.
operationId: deleteUser
parameters:
- name: username
in: path
description: The name that needs to be deleted
required: true
schema:
type: string
responses:
'400':
description: Invalid username supplied
'404':
description: User not found
components:
schemas:
Order:
type: object
properties:
id:
type: integer
format: int64
example: 10
petId:
type: integer
format: int64
example: 198772
quantity:
type: integer
format: int32
example: 7
shipDate:
type: string
format: date-time
status:
type: string
description: Order Status
example: approved
enum:
- placed
- approved
- delivered
complete:
type: boolean
xml:
name: order
Customer:
type: object
properties:
id:
type: integer
format: int64
example: 100000
username:
type: string
example: fehguy
address:
type: array
xml:
name: addresses
wrapped: true
items:
$ref: '#/components/schemas/Address'
xml:
name: customer
Address:
type: object
properties:
street:
type: string
example: 437 Lytton
city:
type: string
example: Palo Alto
state:
type: string
example: CA
zip:
type: string
example: '94301'
xml:
name: address
Category:
type: object
properties:
id:
type: integer
format: int64
example: 1
name:
type: string
example: Dogs
xml:
name: category
User:
type: object
properties:
id:
type: integer
format: int64
example: 10
username:
type: string
example: theUser
firstName:
type: string
example: John
lastName:
type: string
example: James
email:
type: string
example: john@email.com
password:
type: string
example: '12345'
phone:
type: string
example: '12345'
userStatus:
type: integer
description: User Status
format: int32
example: 1
xml:
name: user
Tag:
type: object
properties:
id:
type: integer
format: int64
name:
type: string
xml:
name: tag
Account:
required:
- name
- photoUrls
type: object
properties:
id:
type: integer
format: int64
example: 10
name:
type: string
example: doggie
category:
$ref: '#/components/schemas/Category'
photoUrls:
type: array
xml:
wrapped: true
items:
type: string
xml:
name: photoUrl
tags:
type: array
xml:
wrapped: true
items:
$ref: '#/components/schemas/Tag'
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
xml:
name: pet
ApiResponse:
type: object
properties:
code:
type: integer
format: int32
type:
type: string
message:
type: string
xml:
name: '##default'
requestBodies:
Pet:
description: Pet object that needs to be added to the store
content:
application/json:
schema:
$ref: '#/components/schemas/Account'
application/xml:
schema:
$ref: '#/components/schemas/Account'
UserArray:
description: List of user object
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
securitySchemes:
petstore_auth:
type: oauth2
flows:
implicit:
authorizationUrl: https://petstore3.swagger.io/oauth/authorize
scopes:
write:pets: modify pets in your account
read:pets: read your pets
api_key:
type: apiKey
name: api_key
in: header

59
Old/class.py Normal file
View File

@@ -0,0 +1,59 @@
class Transaction:
def __init__(self, trans_id, from_id, to_id, amount, time, date, description, t_type):
self.trans_id = trans_id
self.from_id = from_id
self.to_id = to_id
self.amount = amount
self.time = time
self.date = date
self.description = description
self.t_type = t_type
class Account:
def __init__(self, account_id, name, balance, created_t, created_d, last_modified, closed, closure_t, closure_d,
notes, transactions=None):
if transactions is None:
transactions = []
self.account_id = account_id
self.name = name
self.balance = balance
self.created_t = created_t
self.created_d = created_d
self.last_modified = last_modified
self.closed = closed
self.closure_t = closure_t
self.closure_d = closure_d
self.notes = notes
self.transactions = transactions
class Customer:
def __init__(self, customer_id, f_name, l_name, phone, email, birthday, address, signup_d, signup_t, notes,
accounts=None):
if accounts is None:
accounts = []
self.customer_id = customer_id
self.f_name = f_name
self.l_name = l_name
self.phone = phone
self.email = email
self.birthday = birthday
self.address = address
self.signup_d = signup_d
self.signup_t = signup_t
self.notes = notes
self.accounts = accounts
#calculate the balance of an account
def calc_balance(account):
balance = 0
for transaction in account.transactions:
if transaction.from_id == account.account_id:
balance -= transaction.amount
elif transaction.to_id == account.account_id:
balance += transaction.amount
return balance

4
Old/manager_account.py Normal file
View File

@@ -0,0 +1,4 @@
# Lucas Mathews - Fontys Student ID: 5023572
# Banking System Manager for Account Class - Version 1

View File

@@ -0,0 +1,24 @@
# Lucas Mathews - Fontys Student ID: 5023572
# Banking System Manager for Transaction Class - Version 1
def add_transaction(transaction_id, transaction_type, amount, timestamp, description, account_number, recipient_account_number):
from api import session, Transaction
new_transaction = Transaction(transaction_id, transaction_type, amount, timestamp, description, account_number, recipient_account_number)
session.add(new_transaction)
session.commit()
return new_transaction
def delete_transaction(transaction_id:int):
DELETE_TRANSACTION = "DELETE FROM transaction WHERE transaction_id=?"
from api import session, Transaction
for transaction in session.query(Transaction).all():
if transaction.transaction_id == transaction_id:
input(f"Are you sure you would like permanenty delete transaction ID: {transaction_id}? WARNING: This action can not be reversed. (Y/N) ")
if input == "Y"or input == "y":
session.execute(DELETE_TRANSACTION, (transaction_id))
print(f"Transaction ID: {transaction_id} has been removed.")
else:
return f"Transaction ID: {transaction_id} has NOT been removed."
return
return f"Transaction ID: {transaction_id} is not found."

196
Old/server.py Normal file
View File

@@ -0,0 +1,196 @@
# Lucas Mathews - Fontys Student ID: 5023572
# Banking System Classes - Version 2
###############
### Modules ###
###############
import sqlite3
import os.path
import datetime
import connexion
from config import CONFIG
#################
### Functions ###
#################
###############
### Classes ###
###############
class Manager:
def __init__():
pass
class Client:
def __init__(self, client_id, name, opening_timestamp, birthdate, address, phone_number, email:str, password, accounts, notes):
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.password = password
self.accounts = accounts
self.notes = notes
#If you call a print function on the object, it will return the following string (does not include password for security reasons)
def __str__(self):
return f"Client ID: {self.client_id}, Name: {self.name}, Birthdate: {self.birthdate}, Address: {self.address}, Phone Number: {self.phone_number}, Email: {self.email}"
#This function will return the account list
def get_accounts(self)->str:
return f"Accounts: {self.accounts}"
#Change details (name, birthdate, address, phone number, email, password)
#Change password
class Account:
def __init__(self, account_id, description, open_timestamp, account_type, balance, enabled, notes, transactions):
self.account_id = account_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 you call a print function on the object, it will return the following string
def __str__(self):
return f"Account ID: {self.account_id}, Description: {self.description}, Open Timestamp: {self.open_timestamp}, Account Type: {self.account_type}, Balance: {self.balance}, Enabled: {self.enabled}, Notes: {self.notes}, Transactions: {self.transactions}"
# This function will return the transaction history of an account
def transaction_history(self, account_id:int):
return self.transactions
#This function will remove the account
def remove_account(self, account_id:int):
REMOVE_ACCOUNT = "DELETE FROM account WHERE account_id=?"
for account in self.accounts:
if account.balance != 0: #If the account has a balance, it can not be removed
return f"Account ID: {account_id} has a balance of {account.balance} and can not be removed."
if account.account_id == account_id: #Check if account exists
input(f"Are you sure you would like permanenty delete account ID: {account_id}? WARNING: This action can not be reversed. (Y/N) ")
if input == "Y"or input == "y": #If the user inputs Y or y, the account will be removed
db_conn = get_db_connection()
cursor = db_conn.cursor()
cursor.execute(REMOVE_ACCOUNT, (account_id, ) )
db_conn.commit()
print(f"Account ID: {account_id} has been removed.")
else:
return f"Account ID: {account_id} has NOT been removed."
return
return f"Account ID: {account_id} is not found."
#This function will return the account balance
def account_balance(account_id:int):
GET_ACCOUNT = "SELECT balance FROM account WHERE account_id = ?"
db_conn = get_db_connection()
cursor = db_conn.cursor()
cursor.execute(GET_ACCOUNT, (account_id) )
resultset = cursor.fetchall()
db_conn.close()
if len(resultset) < 1:
return "Not found", 404
elif len(resultset) > 2:
return "Too many results found.", 500
class Transaction:
def __init__(self, transaction_id, transaction_type, amount, timestamp, description, account_number, recipient_account_number = None):
self.transaction_id = transaction_id
self.transaction_type = transaction_type
self.amount = amount
self.timestamp = timestamp
self.description = description
self.account_number = account_number
self.recipient_account_number = recipient_account_number
def __str__(self):
return f"Transaction ID: {self.transaction_id}, Transaction Type: {self.transaction_type}, Amount: {self.amount}, Timestamp: {self.timestamp}, Description: {self.description} From Account Number: {self.account_number}, Recipient Account Number: {self.recipient_account_number}"
################
### Database ###
################
def Database():
CLIENT_TABLE_CREATION_QUERY = """
CREATE TABLE IF NOT EXISTS client (
client_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
birthdate DATE NOT NULL,
opening_timestamp TIMESTAMP NOT NULL,
address TEXT NOT NULL,
phone_number TEXT NOT NULL,
email TEXT NOT NULL,
password TEXT NOT NULL,
notes TEXT NOT NULL
)
"""
ACCOUNT_TABLE_CREATION_QUERY = """
CREATE TABLE IF NOT EXISTS account (
account_id INTEGER PRIMARY KEY AUTOINCREMENT,
description TEXT NOT NULL,
open_timestamp TIMESTAMP NOT NULL,
account_type TEXT NOT NULL,
balance REAL NOT NULL,
enabled BOOLEAN NOT NULL,
notes TEXT NOT NULL,
client_id INTEGER NOT NULL,
FOREIGN KEY (client_id) REFERENCES client(client_id)
)
"""
TRANSACT_TABLE_CREATION_QUERY = """
CREATE TABLE IF NOT EXISTS transact (
transaction_id INTEGER PRIMARY KEY AUTOINCREMENT,
transaction_type TEXT NOT NULL,
amount REAL NOT NULL,
timestamp TIMESTAMP NOT NULL,
description TEXT NOT NULL,
account_id INTEGER NOT NULL,
recipient_account_id INTEGER,
FOREIGN KEY (account_id) REFERENCES account(account_id)
)
"""
# Check if the database exists
if os.path.exists('bank.db'):
print("Database already exists.")
else:
print("Database does not exist. Creating database.")
# Create the database and the tables if they do not exist, or connect to the database if it does exist
db_connection = sqlite3.connect('bank.db')
db_cursor = db_connection.cursor()
db_cursor.execute(CLIENT_TABLE_CREATION_QUERY)
db_cursor.execute(ACCOUNT_TABLE_CREATION_QUERY)
db_cursor.execute(TRANSACT_TABLE_CREATION_QUERY)
db_connection.commit()
#################
### Connexion ###
#################
def API():
app = connexion.App(__name__)
app.add_api('api.yml')
app.run(host=CONFIG["server"]["listen_address"], port=CONFIG["server"]["port"], debug=CONFIG["server"]["debug"])
################
### Run Code ###
################
if __name__ == "__main__":
Database()
API()