fridge_items.py 文件源码

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

项目:server-application 作者: foodshipper 项目源码 文件源码
def put(self, ean):
        try:
            args = parser.parse_args()
        except Exception:
            return abort(400, message="Invalid arguments")

        with db:
            with db.cursor() as cursor:
                user_id = get_or_create_id(args['token'])

                cursor.execute(
                    "SELECT products.name, products.type FROM fridge_items"
                    " JOIN products ON products.ean=fridge_items.ean"
                    " WHERE fridge_items.user_id=%s AND fridge_items.ean=%s",
                    [user_id[0], ean])
                query = cursor.fetchone()
                if query is None:
                    p = Product.get(ean)  # Produces 404 if not exists
                    cursor.execute("INSERT INTO fridge_items (ean, user_id) VALUES (%s, %s)", [ean, user_id[0]])
                    return p, 201
                else:
                    return {
                        "name": query[0],
                        "type": query[1]
                    }, 200
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号