Skip to content

Commit 5787f83

Browse files
authored
Merge pull request #22 from cdvx/ft-Update-question
Ft update question
2 parents b8cf79a + 4160f4e commit 5787f83

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

app/routes/routes.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ def add_answer(questionId):
8282
return response
8383

8484

85+
@app.route('/api/v1/questions/<int:questionId>', methods=['PATCH'])
86+
def update_question(questionId):
87+
request_data = request.get_json()
88+
updated_question = dict()
89+
ids = [question['questionId'] for question in questionsList]
90+
91+
if questionId in ids:
92+
if "topic" in request_data:
93+
updated_question["topic"] = request_data["topic"]
94+
if "body" in request_data:
95+
updated_question["body"] = request_data["topic"]
96+
97+
for question in questionsList:
98+
if question["questionId"] == questionId:
99+
question.update(updated_question)
100+
101+
response = Response('', status=204)
102+
response.headers['Location'] = "/questions" + str(questionId)
103+
return response
104+
105+
response = Response(json.dumps(['Question not found']), status=404)
106+
return response
107+
85108

86109

87110
def valid_question(questionObject):
@@ -94,4 +117,5 @@ def valid_answer(answerObject):
94117
if 'Qn_Id' in answerObject and 'answerId' in answerObject and 'body' in answerObject :
95118
return True
96119
else:
97-
return False
120+
return False
121+

0 commit comments

Comments
 (0)