class Question: #DB Entity for this wrapper internalData = Entities.Question() #Returns Id of question. def __init__(self, id): self.internalData = DbConnection.session.query(Entities.Question).filter(Entities.Question.id == id).first() if self.internalData == None: raise ValueError def id(self): return self.internalData.id #Return question text of this question. def question(self): return self.internalData.question #Return answer text of this question. def answer(self): return self.internalData.answer #Make a guess with the user provided. def guess(self, user, answer): return #TODO #Provide the hint text to the user provided def hint(self, user): return #TODO #Create a new question and save it to database. @staticmethod def Create(id, question, answer, hint, image): newQuestion = Entities.Question() newQuestion.id = id newQuestion.question = question newQuestion.answer = answer newQuestion.hint = hint newQuestion.image = image DbConnection.session.add(newQuestion) DbConnection.session.commit() #TODO kéne tudni hogy sikeres volt-e! Commit dob vissza ilyet? return True @staticmethod def Delete(id): entity = DbConnection.session.query(Entities.Question).get(id); if(entity != None and entity.id != None) DbConnection.session.delete(entity) DbConnection.session.commit() #Get all questions currently stored in the database. Returns List<Question> @staticmethod def All(): result = [] entities = DbConnection.session.query(Entities.Question).all() for entity in entities: result.append(Question(entity.id)) return result
def Create(id, question, answer, hint, image): newQuestion = Entities.Question() newQuestion.id = id newQuestion.question = question newQuestion.answer = answer newQuestion.hint = hint newQuestion.image = image DbConnection.session.add(newQuestion) DbConnection.session.commit() #TODO kéne tudni hogy sikeres volt-e! Commit dob vissza ilyet? return True