Skip to content

Commit

Permalink
update some comment in api
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjawalpoudel committed Apr 11, 2023
1 parent 5e44ce6 commit d787592
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions app/routes/chatbotResponseCRUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,93 +50,117 @@ def create_chatbot_response_main():
return response(201, body)


# * Design API for update chatbot response details
# Define API Route for updating chatbot response details
@chatbot_response_module.route(
"/<id>", methods=["PUT"], endpoint="update-chatbot-response"
)
@pydantic_validation(ChatbotResponseModel)
@error_handler
def update_chatbot_response_by_id(id):
# get the chatbot response instance with the given id
# Get the chatbot response instance with the given id
chatbot_responses = ChatbotResponse.objects(id=id)

# Check if the chatbot response is None or not
if chatbot_responses.first() == None:
if chatbot_responses.first() is None:
return response(404, {"message": "ChatbotResponse not found"})

# get the update data from the request body
# Get the update data from the request body
data = request.get_json()

# update the chatbot response instance with the new data
# Update the chatbot response instance with the new data
chatbot_responses.update(**data)

# update the modified_date field to the current date and time
# Update the modified_date field to the current date and time
chatbot_responses.update(set__modified_date=datetime.datetime.now)

# Prepare response body
body = {
"data": json.loads(chatbot_responses.first().to_json()),
"message": "ChatbotResponse updated successfully",
}

# Return response with status code 200
return response(200, body)


# * Desing API, which read id and delete chatbot response
# Define API to delete a chatbot response by ID
@chatbot_response_module.route(
"/<id>", methods=["DELETE"], endpoint="delete-chatbot-response"
)
@error_handler
def delete_chatbot_response_by_id(id):
try:
# Get chatbot response by ID and delete it
ChatbotResponse.objects.get(id=id).delete()

# Prepare response body
body = {"message": "Chatbot Response deleted successfully"}

# Return success response with status code 204
return response(204, body)

except DoesNotExist:
# If chatbot response with the given ID is not found, return a 404 response
body = {"message": "Chatbot Response not found"}
return response(404, body)


# * Desing API, which reads all chatbot responses from the database
# Design API to retrieve all chatbot responses from the database
@chatbot_response_module.route(
"/", methods=["GET"], endpoint="get-all-chatbot-response"
)
@error_handler
def get_all_chatbot_responses():
# Retrieve all chatbot responses from the database
chatbot_responses = ChatbotResponse.objects()

# Prepare response body with success message and retrieved chatbot responses
body = {
"msg": "Successfully get all Chatbot Response details.",
"data": json.loads(chatbot_responses.to_json()),
}

# Return response with status code 200
return response(200, body)


# * Design API, which takes document id and returns value of that document
# Define API route to get a single chatbot response by ID
@chatbot_response_module.route(
"/<id>", methods=["GET"], endpoint="get-single-chatbot-response"
)
@error_handler
def get_chatbot_response_by_id(id):
try:
# Retrieve chatbot response with given ID from MongoDB
chatbot_response = ChatbotResponse.objects.get(id=id)

# Prepare response body with chatbot response data
body = {
"msg": "Successfully get single Chatbot Response details.",
"data": json.loads(chatbot_response.to_json()),
}

# Return response with status code 200 and body
return response(200, body)
except DoesNotExist:
# Handle case where chatbot response with given ID is not found
body = {"message": "ChatbotResponse not found"}
return response(404, body)


# * Desing API, which return all possible problems
# Define API route to get all possible problems
@chatbot_response_module.route(
"/problems", methods=["GET"], endpoint="get-possible-problems"
)
@error_handler
def get_possible_problems():
# Define response body with success message and data
body = {
"msg": "Successfully get all possible problems.",
"data": POSSIBLE_PROBLEMS_DICT_METADATA,
}

# Return response with status code 200
return response(200, body)


Expand All @@ -162,14 +186,18 @@ def get_list_of_symptoms(problem):
@error_handler
def get_suggest_remedy():
data = json.loads(request.data)
# Obtain the predicted disease from the data.
disease_prediction = make_suggestion(data)

# Create a response body with the necessary information.
body = {
"msg": "Successfully get all possible suggestion and remedy.",
"data": {
"problem": disease_prediction,
"description": get_description(disease_prediction),
"precution_list": get_precaution(disease_prediction),
"precaution_list": get_precaution(disease_prediction),
},
}

# Return a response with a status code of 200 and the response body.
return response(200, body)

0 comments on commit d787592

Please sign in to comment.