def handle(self) -> HttpResponse: questionID = UUID(self.request.pathParams['questionID']) commentDTO = CommentDTO() commentDTO.body = Body(self.request.body['body']) commentOnQuestion(questionID, commentDTO) response: HttpResponse = HttpResponse(200, None, None) return response
def fetch(self, filteredByQuestionIDs: list = None, filteredByAnswerIDs: list = None, filteredByUUIDs: list = None, filteredByTime: list = None, filteredByVote: list = None, filteredByStatuses: list = None): data = [] if filteredByUUIDs is not None: for uuid in filteredByUUIDs: for c in self.db: if uuid == c['commentID']: data.append(c) elif filteredByQuestionIDs is not None: for uuid in filteredByQuestionIDs: for c in self.db: if 'questionID' in c and uuid.toRepresent() == c['questionID']: data.append(c) elif filteredByAnswerIDs is not None: for uuid in filteredByAnswerIDs: for c in self.db: if 'answerID' in c and uuid.toRepresent() == c['answerID']: data.append(c) else: data = self.db result = [] for c in data: result.append(Comment( commentID=UUID(c['commentID']) if 'commentID' in c else None, body=Body(c['body']) if 'body' in c else None, createdAt=Time(c['createdAt']) if 'createdAt' in c else None, status=CommentStatus(c['status']) if 'status' in c else None, )) return result
def handle(self) -> HttpResponse: questionID = UUID(self.request.pathParams['questionID']) answerDTO = AnswerDTO() answerDTO.body = Body(self.request.body['body']) answerQuestion(questionID, answerDTO) response: HttpResponse = HttpResponse(200, None, None) return response
def fetch(self, filteredByQuestionIDs: list = None, filteredByUUIDs: list = None, filteredByTime: list = None, filteredByVote: list = None, filteredByStatuses: list = None): data = [] if filteredByUUIDs is not None: for uuid in filteredByUUIDs: if str(type(uuid)) == "<class 'str'>": uuid = UUID(uuid) for a in self.db: if uuid.toRepresent() == a['answerID']: data.append(a) elif filteredByQuestionIDs is not None: for uuid in filteredByQuestionIDs: if str(type(uuid)) == "<class 'str'>": uuid = UUID(uuid) for a in self.db: if uuid.toRepresent() == a['questionID']: data.append(a) else: data = self.db result = [] for q in data: comments = Repositories.commentRepository.fetch(filteredByUUIDs=q['comments']) if 'comments' in q else None result.append(Answer( answerID=UUID(q['answerID']) if 'answerID' in q else None, body=Body(q['body']) if 'body' in q else None, createdAt=Time(q['createdAt']) if 'createdAt' in q else None, votes=Vote(q['votes']) if 'votes' in q else None, status=AnswerStatus(q['status']) if 'status' in q else None, comments=comments, )) return result
def handle(self) -> HttpResponse: try: questionID = self.request.pathParams['questionID'] answerDTO = AnswerDTO() answerDTO.body = Body(self.request.body['body']) except Exception as e: raise HttpException(1111, 'questionID and body are required') answerQuestion(UUID(questionID), answerDTO) return HttpResponse(200, None, None)
def handle(self) -> HttpResponse: try: answerID = self.request.pathParams['answerID'] commentDTO = CommentDTO() commentDTO.body = Body(self.request.body['body']) except Exception as e: raise HttpException(1111, 'answerID and body are required') commentOnAnswer(UUID(answerID), commentDTO) return HttpResponse(200, None, None)
def handle(self) -> HttpResponse: if 'title' not in self.request.body: raise HttpException(1111, 'title is required') if 'body' not in self.request.body: raise HttpException(1111, 'body is required') questionDTO = QuestionDTO() questionDTO.title = Title(self.request.body['title']) questionDTO.body = Body(self.request.body['body']) askQuestion(questionDTO) return HttpResponse(200, None, None)
def fetch(self, filteredByUUIDs: list = None, filteredByTitles: list = None, filteredByTime: list = None, filteredByVote: list = None, filteredByStatuses: list = None, filteredByAnswered: list = None, filteredByTags: list = None): data = [] if filteredByUUIDs is not None: for uuid in filteredByUUIDs: for q in self.db: if uuid.toRepresent() == q['questionID']: data.append(q) else: data = self.db result = [] for q in data: answers = Repositories.answerRepository.fetch( filteredByUUIDs=q['answers']) if 'answers' in q else None comments = Repositories.commentRepository.fetch( filteredByUUIDs=q['comments']) if 'comments' in q else None # tags = Repositories.tagRepository.fetch(filteredByUUIDs=q['tags']) if 'tags' in q else None question = Question( questionID=UUID(q['questionID']) if 'questionID' in q else None, title=Title(q['title']) if 'title' in q else None, body=Body(q['body']) if 'body' in q else None, createdAt=Time(q['createdAt']) if 'createdAt' in q else None, votes=Vote(q['votes']) if 'votes' in q else None, bestAnswer=BestAnswer(q['bestAnswer']) if 'bestAnswer' in q else None, status=QuestionStatus(q['status']) if 'status' in q else None, comments=comments, tags=None, answers=answers, ) result.append(question) return result
def editBody(self, newBody): self.body = Body(newBody)