def discount_create(discount, requester_id): """ It stores a new Discount. Parameters: - discount: the Discount containing the new information to store. - requester_id: the string id of the user that is making the request It returns a tuple: - the created Discount (or None in case of errors in the input), - the status (a string indicating whether an error occurred), - the http code indicating the type of error, if any """ try: res = Discount.store(discount, None, requester_id) except (TypeError, ValueError, InvalidKeyException) as e: return None, str(e), 400 except UnauthorizedException, e: return None, str(e), 403
def discount_update(discount, discount_key_str, requester_id): """ It updates an existing Discount. Parameters: - discount: the Discount containing the new information to store. - discount_key_str: the urlsafe key of the Discount to update - requester_id: the string id of the user that is making the request It returns a tuple: - the updated discount (or None in case of errors in the input), - the status (a string indicating whether an error occurred), - the http code indicating the type of error, if any """ try: res = Discount.store( discount, Discount.make_key(None, discount_key_str), requester_id) except (TypeError, ValueError, InvalidKeyException) as e: return None, str(e), 400 except UnauthorizedException, e: return None, str(e), 403