refactored bot code
This commit is contained in:
+49
-5
@@ -11,9 +11,9 @@ class Students:
|
||||
conn = connection.get_db_connection()
|
||||
if not conn:
|
||||
return None
|
||||
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT id,name FROM students");
|
||||
cursor.execute("SELECT id,username FROM students")
|
||||
result = cursor.fetchall()
|
||||
cursor.close()
|
||||
|
||||
@@ -31,9 +31,10 @@ class Students:
|
||||
conn = connection.get_db_connection()
|
||||
if not conn:
|
||||
return None
|
||||
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT id,username, created_at, email, phone_number, last_seen, is_verfied, birthday FROM students WHERE id = %s", (student_id,))
|
||||
cursor.execute(
|
||||
"SELECT id,username, name, created_at, email, phone_number, last_seen, is_verfied, birthday FROM students WHERE id = %s", (student_id,))
|
||||
result = cursor.fetchall()
|
||||
cursor.close()
|
||||
|
||||
@@ -43,4 +44,47 @@ class Students:
|
||||
return None
|
||||
finally:
|
||||
if conn:
|
||||
connection.release_db_connection(conn)
|
||||
connection.release_db_connection(conn)
|
||||
|
||||
|
||||
class Teachers:
|
||||
def getAllTeachers():
|
||||
conn = None
|
||||
try:
|
||||
conn = connection.get_db_connection()
|
||||
if not conn:
|
||||
return None
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT id,username FROM teachers")
|
||||
result = cursor.fetchall()
|
||||
cursor.close()
|
||||
|
||||
return result if result else None
|
||||
except Exception as e:
|
||||
logger.error(f"Database query error in getAllTeachers: {e}")
|
||||
return None
|
||||
finally:
|
||||
if conn:
|
||||
connection.release_db_connection(conn)
|
||||
|
||||
def getTeachertById(teacher_id):
|
||||
conn = None
|
||||
try:
|
||||
conn = connection.get_db_connection()
|
||||
if not conn:
|
||||
return None
|
||||
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT id,username, name, created_at, email, phone_number, last_seen, is_verfied, birthday, about_me, job_title FROM teachers WHERE id = %s", (teacher_id))
|
||||
result = cursor.fetchall()
|
||||
cursor.close()
|
||||
|
||||
return result[0] if result else None
|
||||
except Exception as e:
|
||||
logger.error(f"Database query error in getTeacherById: {e}")
|
||||
return None
|
||||
finally:
|
||||
if conn:
|
||||
connection.release_db_connection(conn)
|
||||
|
||||
Reference in New Issue
Block a user