-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_repository.py
111 lines (100 loc) · 4.52 KB
/
account_repository.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import sqlite3
from db_connect import create_connection
# from account_balance_repository import add_balance_detail
from account import Account
from datetime import date
connection = create_connection()
cursor = connection.cursor()
def get_row_count():
try:
query = ''' SELECT * FROM customer_details'''
execute_query = cursor.execute(query).fetchall()
row_count = len(execute_query)
return row_count
except Exception as exception:
return exception
def add_customer(account_number, account_name, currency,
account_opening_date, last_transaction_date, account_type,
bvn, full_name, status, phoneNumber=None, email=None):
try:
user_account = Account(account_number, account_name, currency,
account_opening_date, last_transaction_date, account_type,
bvn, full_name, status, phoneNumber, email)
print(user_account.status)
customer_id = get_row_count()
if (check_if_customer_exists(user_account.account_number)):
return "Account Exists"
elif(check_if_customer_exists(user_account.account_number) == False):
query = '''INSERT INTO customer_details VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )'''
execute_query = cursor.execute(query, (customer_id, user_account.account_number, user_account.account_name,
user_account.currency, user_account.account_opening_date, user_account.last_transaction_date,
user_account.account_type, user_account.bvn, user_account.full_name,
user_account.phone_number, user_account.email, user_account.status, get_todays_date(), ))
connection.commit()
# connection.close()
return "Account Created"
else:
return "Error"
except Exception as exception:
return exception
def check_if_customer_exists(account_number):
try:
query = ''' SELECT id FROM customer_details WHERE accountNumber=?'''
execute_query = cursor.execute(query, (account_number,)).fetchone()
if execute_query == None:
return False
else:
return True
except Exception as exception:
return exception
def get_customer_id(account_number):
try:
if check_if_customer_exists(account_number):
query = ''' SELECT id FROM customer WHERE accountNumber=?'''
execute_query = cursor.execute(query, (account_number, )).fetchone()
customer_id = execute_query[0]
return customer_id
elif check_if_customer_exists(account_number) == False:
return -1
except Exception as exception:
return exception
def get_account_number(customer_id):
try:
query = ''' SELECT accountNumber FROM customer_details WHERE id=?'''
execute_query = cursor.execute(query, (customer_id, )).fetchone()
return execute_query
except Exception as exception:
return exception
def get_account_details(account_number):
if (check_if_customer_exists(account_number) == True):
try:
query = ''' SELECT id, accountName, currency, accountOpeningDate, lastTransactionDate,
accountType, bvn, fullName, status, phoneNumber, email FROM customer_details WHERE accountNumber=?'''
execute_query = cursor.execute(query, (account_number, )).fetchone()
account_details = {
"id": execute_query[0],
"account_name": execute_query[1],
"currency": execute_query[2],
"account_opening_date": execute_query[3],
"last_transaction_date": execute_query[4],
"account_type": execute_query[5],
"bvn": execute_query[6],
"full_name": execute_query[7],
"status": execute_query[8],
"phone_number": execute_query[9],
"email": execute_query[10],
"account_number": account_number
}
return account_details
except Exception as exception:
return exception
def get_todays_date():
today = str(date.today()).split("-")
date_string = ""
for day in range(len(today)):
date_string = today[day] + "-" + date_string if (day != 0) else today[day] + date_string
return date_string
def create_dummy_account():
print(add_customer("0705809845", "Test", "NGN", get_todays_date(), get_todays_date(), "Savings",
"459459805927438578578559", "Test TestUser", "active", "09052869373", "[email protected]"))
# print(get_account_details("0705809845"))