def get(group_id):
try:
args = parser.parse_args()
except BadRequest:
return abort(400, message="Invalid arguments")
with db:
with db.cursor() as cursor:
user_id = id_from_token(args['token'])
if user_id is None:
return abort(403, message="Token is not allowed to view this group")
cursor.execute("SELECT id FROM groups_rel WHERE user_id=%s AND groups_rel.group_id=%s",
[user_id, group_id])
group = cursor.fetchone()
if group is None:
return abort(403, message="Token is not allowed to view this group")
cursor.execute("SELECT recipe_id, title, upvotes, veto, image, cheap, vegan, vegetarian, duration FROM group_recipes "
"LEFT JOIN rec_recipes ON group_recipes.recipe_id = rec_recipes.id "
"WHERE group_id=%s", [group_id])
recipes = []
for recipe in cursor.fetchall():
recipes.append({
'id': recipe[0],
'title': recipe[1],
'desc': None,
'upvotes': recipe[2],
'veto': recipe[3],
'image': recipe[4],
'cheap': recipe[5],
'vegan': recipe[6],
'vegetarian': recipe[7],
'duration': recipe[8]
})
return recipes
评论列表
文章目录