Ejemplo n.º 1
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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
def router(method, path, request: HttpRequest) -> HttpResponse:

    try:
        if method == POSTQuestion.method and path == POSTQuestion.path:
            return POSTQuestion(request).handle()
        if method == GETQuestions.method and path == GETQuestions.path:
            return GETQuestions(request).handle()
        if method == GETQuestion.method and path == GETQuestion.path:
            return GETQuestion(request).handle()
        if method == DELETEQuestion.method and path == DELETEQuestion.path:
            return DELETEQuestion(request).handle()
        if method == POSTAnswer.method and path == POSTAnswer.path:
            return POSTAnswer(request).handle()
        if method == DELETEAnswer.method and path == DELETEAnswer.path:
            return DELETEAnswer(request).handle()
        if method == GETAnswers.method and path == GETAnswers.path:
            return GETAnswers(request).handle()
        if method == POSTQuestionComment.method and path == POSTQuestionComment.path:
            return POSTQuestionComment(request).handle()
        if method == POSTAnswerComment.method and path == POSTAnswerComment.path:
            return POSTAnswerComment(request).handle()
        if method == GETQuestionComments.method and path == GETQuestionComments.path:
            return GETQuestionComments(request).handle()
        if method == GETAnswerComments.method and path == GETAnswerComments.path:
            return GETAnswerComments(request).handle()
        if method == DELETEQuestionComment.method and path == DELETEQuestionComment.path:
            return DELETEQuestionComment(request).handle()
        if method == DELETEAnswerComment.method and path == DELETEAnswerComment.path:
            return DELETEAnswerComment(request).handle()

    except HttpException as e:
        return HttpResponse(400, {'Content-Type': 'application/json'},
                            json.dumps({
                                'code': e.code,
                                'msg': e.msg
                            }))

    return HttpResponse(404, {'Content-Type': 'application/json'},
                        json.dumps({
                            'code': 1111,
                            'msg': 'Source Not Found'
                        }))
Ejemplo n.º 7
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
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
 def handle(self) -> HttpResponse:
     questionsMap = getQuestions()
     questionsMap = QuestionDTO.toListOfMap(questionsMap)
     for q in questionsMap:
         for i, a in enumerate(q['answers']):
             q['answers'][i] = a['answerID']
         for i, a in enumerate(q['comments']):
             q['comments'][i] = a['commentID']
     response: HttpResponse = HttpResponse(
         200, {'Content-Type': 'application/json'},
         json.dumps(questionsMap))
     return response
Ejemplo n.º 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
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
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
Ejemplo n.º 15
0
 def handle(self) -> HttpResponse:
     response: HttpResponse = HttpResponse()
     softDeleteAnswer(self.request.pathParams['answerID'])
     response.status = 200
     return response