This commit is contained in:
WorldTeacher
2024-06-11 13:28:23 +02:00
parent 09cb0a6084
commit fd692b8c99
11 changed files with 2520 additions and 27 deletions

View File

@@ -76,7 +76,6 @@ class Database:
Returns:
sql.Connection: The active connection to the database
"""
print(self.db_path)
return sql.connect(self.db_path)
def close_connection(self, conn: sql.Connection):
@@ -501,6 +500,31 @@ class Database:
(message["message"], user_id, message["remind_at"], app_id),
)
def getAllMessages(self) -> list[dict[str, str, str, str]]:
"""Get all the messages in the database
Returns:
list[dict[str, str, str, str]]: a list of dictionaries containing the message, the user who added the message, the apparat id and the id of the message
"""
def __get_user_name(user_id):
return self.query_db(
"SELECT username FROM user WHERE id=?", (user_id,), one=True
)[0]
messages = self.query_db("SELECT * FROM messages")
ret = [
{
"message": i[2],
"user": __get_user_name(i[4]),
"appnr": i[5],
"id": i[0],
"remind_at": i[3],
}
for i in messages
]
return ret
def getMessages(self, date: str) -> list[dict[str, str, str, str]]:
"""Get all the messages for a specific date
@@ -529,6 +553,7 @@ class Database:
Args:
message_id (str): the id of the message
"""
logger.log_info(f"Deleting message with id {message_id}")
self.query_db("DELETE FROM messages WHERE id=?", (message_id,))
# Prof data