group_recipes.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:server-application 作者: foodshipper 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号