def getAllAlgs(self) -> Tuple[DBStatus, List[Algorithm]]: try: algs_collection = self.db["algs"] algs_tmp = list(algs_collection.find({})) algs = [] for alg_d in algs_tmp: algs.append(Algorithm.fromDict(alg_d)) except Exception as e: logger.error(f"MongoDBWorker connection failed: {e}") return (DBStatus.s_connection_error, [Algorithm(ERROR_ID)]) logger.debug("Algorithms was found") return (DBStatus.s_ok, algs)
def getAlgByID(self, alg_id) -> Tuple[DBStatus, Algorithm]: try: algs_collection = self.db["algs"] alg_d = algs_collection.find_one({"alg_id": alg_id}) if alg_d is None: logger.error("This algorithm does not exist") return (DBStatus.s_data_issue, Algorithm(ERROR_ID)) except Exception as e: logger.error(f"MongoDBWorker connection failed: {e}") return (DBStatus.s_connection_error, Algorithm(ERROR_ID)) logger.debug("Algorithm was found") return (DBStatus.s_ok, Algorithm.fromDict(alg_d))
def getAllAuthorAlgs(self, author_id) -> Tuple[DBStatus, List[Algorithm]]: try: # check user st, author = self.getUserByID(author_id) if st == DBStatus.s_data_issue: logger.error("This user does not exist") return (DBStatus.s_data_issue, [Algorithm(ERROR_ID)]) # get algs algs_collection = self.db["algs"] algs = [] for alg_id in author.algs_id: alg_d = algs_collection.find_one({ "alg_id": alg_id, "author_id": author_id }) algs.append(Algorithm.fromDict(alg_d)) except Exception as e: logger.error(f"MongoDBWorker connection failed: {e}") return (DBStatus.s_connection_error, [Algorithm(ERROR_ID)]) logger.debug("Algorithms were found") return (DBStatus.s_ok, algs)