def addPurchase(): error = False price = request.json['price'] date = request.json['date'] state = request.json['state'] id_user = request.json['id_user'] id_coupon = request.json['id_coupon'] id_shipping = request.json['id_shipping'] new = Purchase(price, date, state, id_user, id_coupon, id_shipping) try: new.add() except (Exception) as err: error = True return handleError(err) finally: if not (error): return jsonify({'result': 'success'})
def getUserCartInfo(): result = [] error = False user = User() user.id = request.json['user_id'] try: result = user.getCartInfo() if len(result) == 0: new = Purchase() new.id_user = user.id new.add() result = user.getCartInfo() except (Exception) as err: error = True return handleError(err) finally: if not (error): return jsonify({'result': 'success', 'data': result})