Example #1
0
    def put(self, questionid, answerid):
        """modify answer or mark it as preffered"""
        db = Database()
        valid = Validator()
        user_id = get_jwt_identity()
        answer = db.get_by_argument("answers", "question_id", questionid)
        if answer:
            if user_id == answer[2]:
                preffered = modify_arg.parse_args()
                preffer = preffered['preffered']
                if preffer != "True":
                    return {"message": "preffered has no value True"}, 400
                db.update_answer_record("answers", "preffered", preffer,
                                        "answer_id", answerid)
                return {"message": "answer marked as preffered"}, 200

            answer1 = db.get_by_argument("answers", "answer_id", answerid)
            if answer1:
                if user_id == answer1[2]:
                    modifyans = modify_arg.parse_args()
                    eddited_ans = modifyans["answer"]
                    if valid.q_validate(eddited_ans) is False:
                        return {"message": "answer should contain letters"}
                    db.update_answer_record("answers", "reply", eddited_ans,
                                            "answer_id", answerid)
                    return {"message": "answer updated sucessfully"}, 200
        return {"message": "warning you are not authorized"}, 403
Example #2
0
 def post(self, answerid):
     """this route will upvote an answer"""
     db = Database()
     votes = db.get_by_argument("answers", "answer_id", answerid)
     if votes:
         upvote = votes[5] + 1
         db.update_answer_record("answers", "up_vote", upvote, "answer_id",
                                 answerid)
         return {"message": "answer upvoted"}, 201
     return {"message": "No answer by that answer_id"}, 404