Add otp validation + handle key error for add product

This commit is contained in:
PCoder 2019-09-14 00:48:30 +05:30
parent e1f9db5479
commit 8cc568f736
1 changed files with 23 additions and 15 deletions

View File

@ -53,22 +53,30 @@ class AddProduct(Resource):
def post(): def post():
data = request.json data = request.json
logging.debug("Got data: {}".format(str(data))) logging.debug("Got data: {}".format(str(data)))
# TODO: Add validation otp_response = check_otp(data["name"], data["realm"],
data["token"])
if otp_response != 200:
return {"message": "Wrong Credentials"}, 403
product_key = "/v1/products/" try:
product_value = { product_key = "/v1/products/"
"name": data["product_name"], product_value = {
"description": data["product_description"], "name": data["product_name"],
"type": data["product_type"], "description": data["product_description"],
"price": data["product_price"], "type": data["product_type"],
"recurring_duration": data["product_recurring_duration"], "price": data["product_price"],
"recurring_duration_units": "recurring_duration": data["product_recurring_duration"],
data["product_recurring_duration_units"] "recurring_duration_units":
} data["product_recurring_duration_units"]
logging.debug("Adding product data: {}".format(str(product_value))) }
client.put(product_key, product_value, value_in_json=True) logging.debug("Adding product data: {}".format(str(product_value)))
return {"message": client.put(product_key, product_value, value_in_json=True)
"Product {} created".format(data['product_name'])}, 200 return {"message":
"Product {} created".format(data['product_name'])}, 200
except KeyError as ke:
logging.error("KeyError occurred. details = {}".format(str(ke)))
return {"message":
"Missing or wrong parameters"}, 400
class UserRegisterPayment(Resource): class UserRegisterPayment(Resource):