-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.py
More file actions
45 lines (33 loc) · 1.44 KB
/
comment.py
File metadata and controls
45 lines (33 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Blueprint, jsonify
from utility.database import database_cursor
comment_blueprint = Blueprint("comment", __name__)
@comment_blueprint.route("/all", methods=["GET"])
def get_all_comments():
with database_cursor() as cursor:
cursor.callproc("get_all_comments")
comments = cursor.fetchall()
return jsonify(comments)
@comment_blueprint.route("/<int:comment_id>", methods=["GET"])
def get_comment_by_id(comment_id):
with database_cursor() as cursor:
cursor.callproc("get_comment_by_id", (comment_id,))
comment = cursor.fetchone()
return jsonify(comment)
@comment_blueprint.route("/person/<int:person_id>", methods=["GET"])
def get_comments_by_person(person_id):
with database_cursor() as cursor:
cursor.callproc("get_all_comments_by_person", (person_id,))
comments = cursor.fetchall()
return jsonify(comments)
@comment_blueprint.route("/recipe/<int:recipe_id>", methods=["GET"])
def get_comments_by_recipe(recipe_id):
with database_cursor() as cursor:
cursor.callproc("get_all_comments_by_recipe", (recipe_id,))
comments = cursor.fetchall()
return jsonify(comments)
@comment_blueprint.route("/count/recipe/<int:recipe_id>", methods=["GET"])
def get_comment_count_by_recipe(recipe_id):
with database_cursor() as cursor:
cursor.callproc("get_comment_count_by_recipe", (recipe_id,))
count = cursor.fetchone()
return jsonify(count)