products.py 文件源码

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

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

        if args['name'] is None or len(args['name']) == 0:
            args['name'] = "Unknown"

        with db:
            with db.cursor() as cursor:
                cursor.execute("SELECT id FROM product_types WHERE id=%s", [args['type']])
                if cursor.fetchone() is None:
                    abort(400, message="Invalid arguments, product type does not exist.")

                cursor.execute("SELECT name, type FROM products WHERE ean=%s", [ean, ])
                if cursor.fetchone() is None:
                    self.add_product(ean, args['name'], args['type'])
                    return None, 201
                else:
                    cursor.execute("UPDATE products SET name=%s, type=%s WHERE ean=%s",
                                   (args['name'], args['type'], ean))
                    db.commit()
                    return None, 200
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号