Skip to content

Commit 7ee182c

Browse files
authored
Release v1.4.22 beta
Revision 1.4.22_beta
2 parents 376ed3f + 71ca6be commit 7ee182c

File tree

124 files changed

+3122
-19281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+3122
-19281
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Before you can run the Flask API, you need to activate your virtual environment.
112112
To start the Flask API, run the following command within the activated virtual environment:
113113

114114
```bash
115-
python index.py
115+
flask --app index.py run --debug
116116
```
117117

118118
This will start the development server, and your API will be accessible at `http://localhost:5000/`.

api/Dockerfile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
# Use a base image with Python
2-
FROM python:3.9
1+
# Use a slim Python image as the base
2+
FROM python:3.9-slim
33

44
# Set the working directory inside the container
55
WORKDIR /app
66

7-
# Copy the requirements.txt file and install dependencies
7+
# Copy just the requirements file and install dependencies
88
COPY requirements.txt .
99

1010
# Install Python dependencies
1111
RUN pip install --no-cache-dir -r requirements.txt
1212

13-
# Copy all the files from the current directory to the container
13+
# Copy the rest of the application code
1414
COPY . .
1515

16-
# Expose the port your app runs on
16+
# Expose the port Gunicorn will listen on
1717
EXPOSE 5000
1818

19-
# Command to run the Flask application
20-
CMD ["python", "index.py"]
19+
# Command to run the Flask application using Gunicorn with eventlet worker
20+
# Add gunicron & eventlet in requiremens.txt to run in production
21+
CMD ["gunicorn", "-w", "4", "-k", "eventlet", "-b", "0.0.0.0:5000", "index:app"]

api/app_factory.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from flask import Flask
22
from flask_cors import CORS
3-
from flasgger import Swagger
3+
44
from services.transcation_proccessing import start_schedule_background
55

6-
from config.socket import socketio
76
from config.database import db
87
from config.config import ALLOWED_CLIENT_ORIGIN
98

@@ -18,26 +17,16 @@
1817
def create_app():
1918
app = Flask(__name__)
2019
app.config.from_pyfile('config/config.py')
20+
app.config['SECRET_KEY'] = 'transaction_systems_wm_1594'
2121

2222
# Initialize CORS
2323
CORS(app, origins=[ALLOWED_CLIENT_ORIGIN], methods=["POST", "GET", "PUT"])
2424

2525
# Initialize database engine
2626
db.init_app(app)
27-
28-
# Initialize SocketIO for real-time updates
29-
socketio.init_app(app, cors_allowed_origins=ALLOWED_CLIENT_ORIGIN)
30-
31-
# Swagger configuration
32-
app.config['SWAGGER'] = {
33-
'title': 'Transaction Systems API',
34-
'version': '1.32.1',
35-
'uiversion': 3,
36-
'swagger_ui': True,
37-
'specs_route': '/api/',
38-
'swagger_ui_css': '/static/swagger-ui.css'
39-
}
40-
Swagger(app)
27+
28+
from config.socket import socket_io
29+
socket_io.init_app(app, cors_allowed_origins=ALLOWED_CLIENT_ORIGIN)
4130

4231
# Register blueprints
4332
app.register_blueprint(auth_blueprint)
@@ -47,7 +36,7 @@ def create_app():
4736
app.register_blueprint(current_account_blueprint)
4837
app.register_blueprint(currencies_blueprint)
4938
app.register_blueprint(transaction_blueprint)
50-
39+
5140
# Start Transaction System service in background
5241
start_schedule_background(app)
5342

api/config/exlude_docs_str.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

api/config/socket.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
from flask_socketio import Namespace
21
from flask_socketio import SocketIO
32

4-
# Define new realtime socket
5-
socketio = SocketIO()
3+
socket_io = SocketIO()
64

7-
# Define a custom namespace
8-
class RealTimeNamespace(Namespace):
9-
def on_connect(self):
10-
print('Client connected to realtime updates service')
5+
@socket_io.on("connect")
6+
def connection():
7+
print("Connected!")
118

12-
def on_disconnect(self):
13-
print('Client disconnected from realtime updates service')
14-
15-
socketio.on_namespace(RealTimeNamespace('/api/realtime'))
9+
@socket_io.on("disconnect")
10+
def connection():
11+
print("Disconnected!")

api/controllers/credit_card.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@
55

66
# Method to create a new credit card
77
def create_credit_card(data):
8-
"""
9-
Create a credit card record submitted by a user via form.
10-
11-
Args:
12-
data (dict): A dictionary containing card information: 'card_number', 'cardholder_name', 'expiry_date', 'cvv', 'uid'.
13-
14-
Returns:
15-
bool: True if the credit card is successfully created, False otherwise.
16-
17-
Example:
18-
data = {
19-
'card_number': '1234567890123456',
20-
'cardholder_name': 'John Doe',
21-
'expiry_date': '12/25',
22-
'cvv': '123',
23-
'uid': 1
24-
}
25-
result = create_credit_card(data)
26-
print(result) # True or False
27-
"""
288
card_number = data.get('card_number')
299
cardholder_name = data.get('cardholder_name')
3010
expiry_date = data.get('expiry_date')
@@ -51,19 +31,6 @@ def create_credit_card(data):
5131

5232
# Method to check is credit card exist
5333
def check_credit_card_by_uid(uid):
54-
"""
55-
Check if a user has a credit card by user ID.
56-
57-
Args:
58-
uid (int): The user ID to check.
59-
60-
Returns:
61-
bool: True if the user has a credit card, False otherwise.
62-
63-
Example:
64-
has_card = check_credit_card_by_uid(1)
65-
print(has_card) # True or False
66-
"""
6734
try:
6835
card = db.session.query(CreditCard).filter(CreditCard.uid == uid).first()
6936
return card is not None # Return True if user has credit card, False otherwise
@@ -72,19 +39,6 @@ def check_credit_card_by_uid(uid):
7239

7340
# Method to get all credit cards owned by user
7441
def get_all_credit_cards_by_uid(uid):
75-
"""
76-
Retrieve all credit cards associated with a user ID.
77-
78-
Args:
79-
uid (int): The user ID.
80-
81-
Returns:
82-
list: A list containing serialized credit card data for the given user ID. Returns None if an error occurs.
83-
84-
Example:
85-
credit_cards = get_all_credit_cards_by_uid(1)
86-
print(credit_cards) # List of credit card data or None
87-
"""
8842
try:
8943
credit_cards = db.session.query(CreditCard).filter(CreditCard.uid == uid).all()
9044
return [card.serialize() for card in credit_cards]
@@ -93,20 +47,6 @@ def get_all_credit_cards_by_uid(uid):
9347

9448
# Method to verify user's credit card
9549
def update_verified_field(card_number, verified_status):
96-
"""
97-
Update the 'verified' field of a credit card by card number.
98-
99-
Args:
100-
card_number (str): The card number of the credit card.
101-
verified_status (bool): The status to set for the 'verified' field.
102-
103-
Returns:
104-
bool: True if the 'verified' field is successfully updated, False otherwise.
105-
106-
Example:
107-
result = update_verified_field('1234567890123456', True)
108-
print(result) # True or False
109-
"""
11050
try:
11151
credit_card = db.session.query(CreditCard).filter(CreditCard.card_number == card_number).first()
11252
if credit_card:

api/controllers/current_account.py

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,9 @@
11
from decimal import Decimal
2-
from services.account_number_generator import generate_account_number
32
from models.current_account import CurrentAccount
43
from config.database import db
54

65
# Method to create a new current account
76
def create_current_account(account_number, balance, currency, card_number, uid):
8-
"""
9-
Creates a new current account.
10-
11-
Args:
12-
account_number (str): The account number of the current account.
13-
balance (float): The initial balance in the account.
14-
currency (str): The currency type of the account.
15-
card_number (str): The associated credit card number.
16-
uid (int): The user ID associated with the account.
17-
18-
Returns:
19-
True or False: Returns True if the account is created successfully,
20-
otherwise returns False.
21-
22-
Example:
23-
is_created = create_current_account("1234567890", 1000.00, "USD", "1234567890123456", 1)
24-
"""
257
try:
268
new_account = CurrentAccount(
279
account_number=account_number,
@@ -38,48 +20,22 @@ def create_current_account(account_number, balance, currency, card_number, uid):
3820
return False
3921

4022
# Method to check if an account exists based on UID and currency
41-
def check_account_exists(uid, card_number, currency):
42-
"""
43-
Checks if an account exists based on user ID, card number and currency.
44-
45-
Args:
46-
uid (int): The user ID associated with the account.
47-
card_number (str): The user card number associated with the account.
48-
currency (str): The currency type of the account.
49-
50-
Returns:
51-
int or None: Returns the account ID if the account exists, otherwise returns None.
52-
53-
Example:
54-
account_id = check_account_exists(1, "3434 3434 5667 2223", "USD")
55-
"""
23+
def check_account_exists_by_uid_cardnumber_currency(uid, card_number, currency):
5624
try:
5725
account = db.session.query(CurrentAccount).filter_by(card_number=card_number, uid=uid, currency=currency).first()
5826
return account.account_id if account else None
5927
except Exception as e:
6028
return None
6129

6230
# Method to check if an account exists based on UID and currency
63-
def get_account_number(uid, card_number):
31+
def get_account_number_by_uid_and_cardnumber(uid, card_number):
6432
try:
6533
account = db.session.query(CurrentAccount).filter_by(card_number=card_number, uid=uid).first()
6634
return account
6735
except Exception as e:
6836
return None
6937

7038
def get_current_account_by_id(account_id):
71-
"""
72-
Checks if a current account exists based on the account ID.
73-
74-
Args:
75-
account_id (int): The account ID to check.
76-
77-
Returns:
78-
bool: Returns an account if the account exists, otherwise returns None.
79-
80-
Example:
81-
account_exists = check_current_account_exists(123)
82-
"""
8339
try:
8440
# Query the database to find the account with the given account ID
8541
account = db.session.query(CurrentAccount).filter_by(account_id=account_id).first()
@@ -89,19 +45,6 @@ def get_current_account_by_id(account_id):
8945

9046
# Method to update the balance of an account by account ID
9147
def update_account_balance(account_id, amount):
92-
"""
93-
Updates the balance of an account by account ID.
94-
95-
Args:
96-
account_id (int): The unique identifier for the account.
97-
amount (float): The new amout to be added in the account.
98-
99-
Returns:
100-
bool: True if the account balance is successfully updated, otherwise False.
101-
102-
Example:
103-
success = update_account_balance(1, 1500.00)
104-
"""
10548
try:
10649
account = db.session.query(CurrentAccount).get(account_id)
10750
if account:
@@ -115,7 +58,7 @@ def update_account_balance(account_id, amount):
11558
return False
11659

11760
# Method to get account by account number
118-
def get_account_by_number(account_number):
61+
def get_account_by_account_number(account_number):
11962
try:
12063
account = db.session.query(CurrentAccount).filter_by(account_number=str(account_number).strip()).first()
12164
return account
@@ -131,26 +74,10 @@ def get_account_by_number_and_currency(account_number, currency):
13174
return None
13275

13376
# Method to get all current accounts connected with credit card
134-
def get_all_current_accounts(card_number):
135-
"""
136-
Retrieves all accounts associated with a specified credit card number.
137-
138-
Args:
139-
card_number (str): The credit card number to search for.
140-
141-
Returns:
142-
list or None: A list of CurrentAccount objects associated with the specified card_number.
143-
Returns None if an error occurs during the query.
144-
145-
Example:
146-
accounts = get_all_current_accounts('1234567890123456')
147-
if accounts:
148-
for account in accounts:
149-
print(f"Account ID: {account.account_id}, Balance: {account.balance}, Currency: {account.currency}")
150-
"""
77+
def get_all_current_accounts_by_cardnumber(card_number):
15178
try:
15279
accounts = db.session.query(CurrentAccount).filter(CurrentAccount.card_number == card_number).all()
153-
return accounts
80+
return [account.serialize() for account in accounts]
15481
except Exception as e:
15582
return None
15683

@@ -164,7 +91,7 @@ def exchange_funds(account_id, new_balance, amount_to_exchange, currency_to_conv
16491
if float(account.balance) < float(amount_to_exchange) or float(amount_to_exchange) < 0.0:
16592
response['error'] = "Insufficient funds on the account"; response['code'] = 400
16693
else:
167-
account_id_destination = check_account_exists(account.uid, account.card_number, currency_to_convert)
94+
account_id_destination = check_account_exists_by_uid_cardnumber_currency(account.uid, account.card_number, currency_to_convert)
16895

16996
# If current account already has account with convert currency then just update it
17097
if account_id_destination:

0 commit comments

Comments
 (0)