feat: add documentation for ELSA and extend functionality, include new icons and update semester logic
This commit is contained in:
@@ -11,7 +11,6 @@ from omegaconf import OmegaConf
|
||||
from src.backend.db import (
|
||||
CREATE_ELSA_FILES_TABLE,
|
||||
CREATE_ELSA_MEDIA_TABLE,
|
||||
CREATE_ELSA_PROF_TABLE,
|
||||
CREATE_ELSA_TABLE,
|
||||
CREATE_TABLE_APPARAT,
|
||||
CREATE_TABLE_APPKONTOS,
|
||||
@@ -1203,7 +1202,8 @@ class Database:
|
||||
Returns:
|
||||
list[str]: a list of all the roles
|
||||
"""
|
||||
return self.query_db("SELECT role FROM user")
|
||||
roles = self.query_db("SELECT role FROM user")
|
||||
return [i[0] for i in roles]
|
||||
|
||||
def checkUsername(self, user) -> bool:
|
||||
"""a check to see if the username is already present in the database
|
||||
@@ -1311,26 +1311,29 @@ class Database:
|
||||
)
|
||||
|
||||
# ELSA
|
||||
def createElsaProf(self, name):
|
||||
"""create a new professor in the database for the ELSA system
|
||||
|
||||
Args:
|
||||
name (str): the name of the professor
|
||||
"""
|
||||
self.query_db("INSERT INTO elsa_prof (name) VALUES (?)", (name,))
|
||||
|
||||
def createElsaApparat(self, date, prof_id, semester):
|
||||
def createElsaApparat(self, date, prof_id, semester) -> int:
|
||||
"""create a new apparat in the database for the ELSA system
|
||||
|
||||
Args:
|
||||
date (str): the name of the apparat
|
||||
prof_id (int): the id of the professor
|
||||
semester (str): the semester the apparat is created in
|
||||
|
||||
Returns:
|
||||
int: the id of the apparat
|
||||
"""
|
||||
self.query_db(
|
||||
"INSERT OR IGNORE INTO elsa (date, prof_id, semester) VALUES (?,?,?)",
|
||||
(date, prof_id, semester),
|
||||
)
|
||||
# get the id of the apparat
|
||||
apparat_id = self.query_db(
|
||||
"SELECT id FROM elsa WHERE date=? AND prof_id=? AND semester=?",
|
||||
(date, prof_id, semester),
|
||||
one=True,
|
||||
)[0]
|
||||
return apparat_id
|
||||
|
||||
def updateElsaApparat(self, date, prof_id, semester, elsa_id):
|
||||
"""update an ELSA apparat in the database
|
||||
@@ -1446,9 +1449,13 @@ class Database:
|
||||
Returns:
|
||||
int: the id of the ELSA apparat
|
||||
"""
|
||||
prof_id = self.getElsaProfId(prof)
|
||||
if prof_id is None:
|
||||
return None
|
||||
|
||||
data = self.query_db(
|
||||
"SELECT id FROM elsa WHERE prof_id=? AND semester=? AND date=?",
|
||||
(prof, semester, date),
|
||||
(prof_id, semester, date),
|
||||
one=True,
|
||||
)
|
||||
if data is None:
|
||||
@@ -1497,22 +1504,7 @@ class Database:
|
||||
if data:
|
||||
return data[0][0]
|
||||
else: return None
|
||||
|
||||
def createElsaProf(self, profname)-> int:
|
||||
pId = self.getElsaProfId(profname)
|
||||
if pId:
|
||||
return pId
|
||||
query = f"INSERT INTO elsa_prof (fullname) VALUES ('{profname}')"
|
||||
self.query_db(query)
|
||||
return self.getElsaProfId(profname)
|
||||
|
||||
def getElsaProf(self, prof_id)->str:
|
||||
query = f"SELECT fullname FROM elsa_prof WHERE id = '{prof_id}'"
|
||||
data = self.query_db(query)
|
||||
if data:
|
||||
return data[0][0]
|
||||
else: return None
|
||||
|
||||
|
||||
def getElsaProfs(self)->list[str]:
|
||||
query = f"SELECT fullname FROM elsa_prof"
|
||||
data = self.query_db(query)
|
||||
@@ -1521,6 +1513,14 @@ class Database:
|
||||
else: return []
|
||||
|
||||
def getProfId(self, profdata: dict|Prof):
|
||||
"""Get the prof ID based on the profdata
|
||||
|
||||
Args:
|
||||
profdata (dict | Prof): either a dictionary containing the prof data or a Prof object
|
||||
|
||||
Returns:
|
||||
int | None: The id of the prof or None if not found
|
||||
"""
|
||||
conn = self.connect()
|
||||
cursor = conn.cursor()
|
||||
if isinstance(profdata, Prof):
|
||||
@@ -1557,8 +1557,61 @@ class Database:
|
||||
if result:
|
||||
return Prof().from_tuple(result)
|
||||
else: return Prof()
|
||||
def getProfNameByApparat(self, apprarat_id):
|
||||
query = f"SELECT prof_id from semesterapparat WHERE appnr = '{apprarat_id}'"
|
||||
|
||||
def getProfIDByApparat(self, apprarat_id):
|
||||
"""Get the prof id based on the semesterapparat id from the database
|
||||
|
||||
Args:
|
||||
apprarat_id (int): Number of the apparat
|
||||
|
||||
Returns:
|
||||
int | None: The id of the prof or None if not found
|
||||
"""
|
||||
query = f"SELECT prof_id from semesterapparat WHERE id = '{apprarat_id}' and deletion_status = 0"
|
||||
data = self.query_db(query)
|
||||
if data:
|
||||
return data[0][0]
|
||||
else:
|
||||
return None
|
||||
|
||||
def copyBookToApparat(self, book_id, apparat):
|
||||
# get book data
|
||||
new_apparat_id = apparat
|
||||
new_prof_id = self.getProfIDByApparat(new_apparat_id)
|
||||
query = f"""
|
||||
INSERT INTO media (bookdata, app_id, prof_id, deleted, available, reservation)
|
||||
SELECT
|
||||
bookdata,
|
||||
'{new_apparat_id}',
|
||||
'{new_prof_id}',
|
||||
0,
|
||||
available,
|
||||
reservation
|
||||
FROM media
|
||||
where id = '{book_id}'"""
|
||||
connection = self.connect()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(query)
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def moveBookToApparat(self, book_id, appratat):
|
||||
"""Move the book to the new apparat
|
||||
|
||||
Args:
|
||||
book_id (int): the ID of the book
|
||||
appratat (int): the ID of the new apparat
|
||||
"""
|
||||
# get book data
|
||||
query = f"UPDATE media SET app_id = '{appratat}' WHERE id = '{book_id}'"
|
||||
connection = self.connect()
|
||||
cursor = connection.cursor()
|
||||
cursor.execute(query)
|
||||
connection.commit()
|
||||
connection.close()
|
||||
|
||||
def getApparatNameByAppNr(self, appnr):
|
||||
query = f"SELECT name FROM semesterapparat WHERE appnr = '{appnr}' and deletion_status = 0"
|
||||
data = self.query_db(query)
|
||||
if data:
|
||||
return data[0][0]
|
||||
|
||||
Reference in New Issue
Block a user