add accounting page and fix issue with db selects
This commit is contained in:
@@ -47,6 +47,9 @@ class AccountingService:
|
||||
balance_buffer += transaction.value
|
||||
return balance_buffer
|
||||
|
||||
def get_transaction_history(self, user_id: int) -> list[Transaction]:
|
||||
return self._db_service.get_all_transactions_for_user(user_id)
|
||||
|
||||
@staticmethod
|
||||
def make_euro_string_from_int(cent_int: int) -> str:
|
||||
""" Internally, all money values are cents as ints. Only when showing them to the user we generate a string. Prevents float inaccuracy. """
|
||||
|
||||
@@ -63,6 +63,7 @@ class DatabaseService:
|
||||
def get_user_by_name(self, user_name: str) -> Optional[User]:
|
||||
cursor = self._get_cursor()
|
||||
cursor.execute("SELECT * FROM users WHERE user_name=?", (user_name,))
|
||||
self._connection.commit()
|
||||
result = cursor.fetchone()
|
||||
if not result:
|
||||
return
|
||||
@@ -71,6 +72,7 @@ class DatabaseService:
|
||||
def get_user_by_id(self, user_id: int) -> Optional[User]:
|
||||
cursor = self._get_cursor()
|
||||
cursor.execute("SELECT * FROM users WHERE user_id=?", (user_id,))
|
||||
self._connection.commit()
|
||||
result = cursor.fetchone()
|
||||
if not result:
|
||||
return
|
||||
@@ -79,6 +81,7 @@ class DatabaseService:
|
||||
def get_user_by_mail(self, user_mail: str) -> Optional[User]:
|
||||
cursor = self._get_cursor()
|
||||
cursor.execute("SELECT * FROM users WHERE user_mail=?", (user_mail.lower(),))
|
||||
self._connection.commit()
|
||||
result = cursor.fetchone()
|
||||
if not result:
|
||||
return
|
||||
@@ -135,6 +138,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute("SELECT * FROM transactions WHERE user_id=?", (user_id,))
|
||||
self._connection.commit()
|
||||
result = cursor.fetchall()
|
||||
except mariadb.Error as e:
|
||||
logger.error(f"Error getting all transactions for user: {e}")
|
||||
@@ -167,6 +171,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute("SELECT * FROM news INNER JOIN users ON news.news_author = users.user_id WHERE news_date BETWEEN ? AND ?;", (dt_start, dt_end))
|
||||
self._connection.commit()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error fetching news: {e}")
|
||||
return []
|
||||
@@ -189,6 +194,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute("SELECT * FROM tickets INNER JOIN users ON tickets.user = users.user_id;", ())
|
||||
self._connection.commit()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error fetching tickets: {e}")
|
||||
return []
|
||||
@@ -208,6 +214,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute("SELECT * FROM tickets INNER JOIN users ON tickets.user = users.user_id WHERE user_id=?;", (user_id, ))
|
||||
self._connection.commit()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error fetching ticket for user: {e}")
|
||||
return
|
||||
@@ -273,6 +280,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute("SELECT seats.*, users.* FROM seats LEFT JOIN users ON seats.user = users.user_id;")
|
||||
self._connection.commit()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error getting seats table: {e}")
|
||||
return results
|
||||
@@ -303,6 +311,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute("SELECT * FROM catering_menu_items;")
|
||||
self._connection.commit()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error fetching menu items: {e}")
|
||||
return results
|
||||
@@ -323,6 +332,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute("SELECT * FROM catering_menu_items WHERE catering_menu_item_id = ?;", (menu_item_id, ))
|
||||
self._connection.commit()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error fetching menu items: {e}")
|
||||
return
|
||||
@@ -439,6 +449,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute(query)
|
||||
self._connection.commit()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error getting orders: {e}")
|
||||
return fetched_orders
|
||||
@@ -467,6 +478,7 @@ class DatabaseService:
|
||||
"WHERE order_id = ?;",
|
||||
(order_id, )
|
||||
)
|
||||
self._connection.commit()
|
||||
except Exception as e:
|
||||
logger.warning(f"Error getting order items: {e}")
|
||||
return result
|
||||
@@ -498,6 +510,7 @@ class DatabaseService:
|
||||
cursor = self._get_cursor()
|
||||
try:
|
||||
cursor.execute("SELECT (picture) FROM user_profile_picture WHERE user_id = ?", (user_id, ))
|
||||
self._connection.commit()
|
||||
r = cursor.fetchone()
|
||||
if r is None:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user