From 4dbe65ba3d0e8417a71d27fa2e7d4a5e3c34afcc Mon Sep 17 00:00:00 2001 From: nathan <nathan9.baker@live.uwe.ac.uk> Date: Mon, 18 Nov 2024 10:59:03 +0000 Subject: [PATCH] started ERD and database setup --- Diagrams/Class_Diagram.asta.lock | 0 src/cinemaObj.py | 9 ++++++++- src/dbfunc.py | 28 +++++++++++++++++++++++++++- src/staffUser.py | 16 +++++++--------- 4 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 Diagrams/Class_Diagram.asta.lock diff --git a/Diagrams/Class_Diagram.asta.lock b/Diagrams/Class_Diagram.asta.lock new file mode 100644 index 0000000..e69de29 diff --git a/src/cinemaObj.py b/src/cinemaObj.py index 12de64b..ac86e52 100644 --- a/src/cinemaObj.py +++ b/src/cinemaObj.py @@ -23,7 +23,7 @@ class Cinema(object): def create_screen(self): raise NotImplementedError() # obj_screen = Screen(capacity=0, sizeH=9,sizeW=16,resolutionH=1080,resolutionW=1920,isIMAX=False) - # obj_screen.save() + # cinema_screeens .append obj_screen def update_screen(self, screen:Screen, sizeHeight:float, sizeWidth:float, resolutionHeight:int, resolutionWidth:int, capacity:int) -> None: raise NotImplementedError() @@ -45,6 +45,13 @@ class Cinema(object): # do we need this? need to test if we can use cinema.listings.remove() raise NotImplementedError() + def updateFromDataBase(self) -> None: + # call dbFunc + # gets data in form of json + # gets pricing data + # convert to dict? + # update self data with new values. + raise NotImplementedError() if __name__ == "__main__": diff --git a/src/dbfunc.py b/src/dbfunc.py index bb66166..067b8ca 100644 --- a/src/dbfunc.py +++ b/src/dbfunc.py @@ -40,4 +40,30 @@ def getConnection(db=""): logging.error(err) else: logging.error("Connected to server, without database.") - return conn \ No newline at end of file + return conn + +def selectFromTbl(table, dbname, *args): + logging.debug(f"running slect statement with values: tablename='{table}'', dbname='{dbname}'', {args}") + conn = getConnection(db=dbname) + if conn != None: + if conn.is_connected(): + SELECT_STATEMENT = f"SELECT " + for arg in args: + SELECT_STATEMENT.append(f"{arg}, ") + SELECT_STATEMENT.removesuffix(", ") + SELECT_STATEMENT.append(f" from {table};") + + dbcursor = conn.cursor() + dbcursor.execute(f"USE {dbname}") + dbcursor.execute(SELECT_STATEMENT) + logging.info("SELECT statement executed successfully.") + dataOut = dbcursor.fetchall() + logging.debug(f"dataOut: {dataOut}") + dbcursor.close() + conn.close() + else: + logging.error("conn not connected") + raise ConnectionError() + else: + logging.error("conn returned NoneType") + raise ConnectionAbortedError() diff --git a/src/staffUser.py b/src/staffUser.py index e8b7c94..c770fe8 100644 --- a/src/staffUser.py +++ b/src/staffUser.py @@ -22,15 +22,6 @@ class StaffUser(object): userType = "BookingStaff" return f"{userType} user object(userID={self.userID}, userName={self.userName}, userPass={self.userPass})" -# @property -# def options_list(self) -> dict: -# """_summary_ -# functions in a dict, to be used as labels and callable function pairs -# Returns: -# dict: _description_ -# """ -# options:dict = {"View film Listings":self.viewFilmListing, "Create booking":self.createBooking, "Logout":self.logout} -# return options def save(self): """save self to db.""" @@ -63,6 +54,13 @@ class StaffUser(object): def manageBooking(self): raise NotImplementedError() + + def updateFromDataBase(self) -> None: + # call dbFunc + # gets dbData in form of json + # convert to dict? + # update self data with new values. + raise NotImplementedError() -- GitLab