Example #1
0
 def update(self, newComment: Comment):
     for c in self.db:
         if c['commentID'] == newComment.commentID.UUID:
             self.delete(newComment.commentID)
             if c['questionID'] is not None:
                 self.save(UUID(c['questionID']), None, newComment)
             if c['answerID'] is not None:
                 self.save(None, UUID(c['answerID']), newComment)
             return
Example #2
0
    def handle(self) -> HttpResponse:
        try:
            questionID = self.request.pathParams['questionID']
        except Exception as e:
            raise HttpException(1111, 'questionID is required')

        if 'hard' in self.request.headers:
            hardDeleteQuestion(UUID(questionID))
        else:
            softDeleteQuestion(UUID(questionID))

        return HttpResponse(200, None, None)
Example #3
0
 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'])
     commentDTO = CommentDTO()
     commentDTO.body = Body(self.request.body['body'])
     commentOnQuestion(questionID, commentDTO)
     response: HttpResponse = HttpResponse(200, None, None)
     return response
Example #5
0
 def handle(self) -> HttpResponse:
     questionID = UUID(self.request.pathParams['questionID'])
     comments = getQuestionComments(questionID)
     comments = CommentDTO.toListOfMap(comments)
     response: HttpResponse = HttpResponse(
         200, {'Content-Type': 'application/json'}, json.dumps(comments))
     return response
Example #6
0
 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 handle(self) -> HttpResponse:
     questionID = UUID(self.request.pathParams['questionID'])
     answers = getAnswersOfQuestion(questionID)
     answers = AnswerDTO.toListOfMap(answers)
     response: HttpResponse = HttpResponse(
         200, {'Content-Type': 'application/json'}, json.dumps(answers))
     return response
Example #8
0
 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:
            commentID = self.request.pathParams['commentID']
        except Exception as e:
            raise HttpException(1111, 'commentID is required')

        deleteComment(UUID(commentID))

        return HttpResponse(200, None, None)
Example #10
0
    def handle(self) -> HttpResponse:
        try:
            answerID = self.request.pathParams['answerID']
        except Exception as e:
            raise HttpException(1111, 'answerID are required')

        comments = getAnswerComments(UUID(answerID))
        commentsMap = CommentDTO.toListOfMap(comments)

        response: HttpResponse = HttpResponse(200, {'Content-Type': 'application/json'}, json.dumps(commentsMap))
        return response
Example #11
0
    def handle(self) -> HttpResponse:
        try:
            questionID = self.request.pathParams['questionID']
        except Exception as e:
            raise HttpException(1111, 'questionID are required')

        answers = getAnswersOfQuestion(UUID(questionID))
        answersMap = AnswerDTO.toListOfMap(answers)

        response: HttpResponse = HttpResponse(
            200, {'Content-Type': 'application/json'}, json.dumps(answersMap))
        return response
Example #12
0
class BestAnswer:
    def __init__(self, answerID):
        self.ANSWER_ID = UUID(answerID)
        self.DATE = Time(time.time())

    def toRepresent(self):
        return {
            f'{self.ANSWER_ID=}'.split('=')[0].split('.')[1].lower():
            self.ANSWER_ID.toRepresent(),
            f'{self.DATE=}'.split('=')[0].split('.')[1].lower():
            self.DATE.toRepresent()
        }
Example #13
0
    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)
Example #14
0
    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)
Example #15
0
    def handle(self) -> HttpResponse:
        try:
            questionID = self.request.pathParams['questionID']
        except Exception as e:
            raise HttpException(1111, 'questionID is required')

        try:
            questionsMap = getQuestion(UUID(questionID))
            questionsMap = QuestionDTO.toMap(questionsMap)
        except Exception as e:
            raise HttpException(1111, 'no question by that ID')

        for i, a in enumerate(questionsMap['answers']):
            questionsMap['answers'][i] = a['answerID']
        for i, a in enumerate(questionsMap['comments']):
            questionsMap['comments'][i] = a['commentID']
        response: HttpResponse = HttpResponse(
            200, {'Content-Type': 'application/json'},
            json.dumps(questionsMap))
        return response
Example #16
0
 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
Example #17
0
 def generate(self) -> UUID:
     return UUID(str(uuid.uuid4())[:8])
Example #18
0
 def update(self, newAnswer: Answer):
     for a in self.db:
         if a['answerID'] == newAnswer.answerID.UUID:
             self.delete(newAnswer.answerID)
             self.save(UUID(a['questionID']), newAnswer)
             return
Example #19
0
 def __init__(self, answerID):
     self.ANSWER_ID = UUID(answerID)
     self.DATE = Time(time.time())