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
评论列表
文章目录