def history_add_multiple(): user_id = get_jwt_identity() parking_id = [1,2,3,4,5,6,7,8] for parking in parking_id: history_inst = History(user_id = user_id, parking_id = parking) history_inst.save()
def add_history(): auth_header = request.headers.get('Authorization') if auth_header: auth_token = auth_header.split(" ")[1] else: responseObject = { 'status': 'failed', 'message': 'No authorization header found' } return make_response(jsonify(responseObject)), 401 user_id = User.decode_auth_token(auth_token) user = User.get_by_id(user_id) # save link that has been clicked on clicked_link = request.get_json('link') history = History(link=clicked_link, user_id=user.id) history.save() # sendgrid send email to user.email send_email(email)
def post(self): json_data = request.get_json() current_user = get_jwt_identity() try: data = history_schema.load(data=json_data) except ValidationError as errors: return {'message': 'Validation errors', 'errors': errors.messages}, HTTPStatus.BAD_REQUEST history = History(**data) history.user_id = current_user history.save() return history_schema.dump(history), HTTPStatus.CREATED
def add_history(): clicked_link = request.get_json() auth_header = request.headers.get('Authorization') if not auth_header: responseObject = { 'status': 'failed', 'message': 'No JWT in Authorization Header' } return make_response(jsonify(responseObject)), 401 # decode the auth_token to get the user_id auth_token = auth_header.split(" ")[1] user_id = User.decode_auth_token(auth_token) current_user = User.get_by_id(user_id) # save link that has been clicked on if current_user and clicked_link: email = current_user.email name = current_user.name # sendgrid send email to user.email send_email(email) history = History( link=clicked_link['link'], user_id=current_user.id) if history.save(): responseObject = { 'status': 'success' } return make_response(jsonify(responseObject)), 201 else: responseObject = { 'status': 'failed', 'message': 'History not saved' } return make_response(jsonify(responseObject)), 401 else: responseObject = { 'status': 'failed', 'message': 'No authorization header found' } return make_response(jsonify(responseObject)), 401
def history_add(): user_id = get_jwt_identity() user_inst = User.get_by_id(user_id) parking_id = request.json.get('parking_id') parking_inst = Parking.get_by_id(parking_id) floor_inst = Floor.get_by_id(parking_inst.floor_id) mall_inst = Mall.get_by_id(floor_inst.mall_id) history_inst = History(user_id = user_id, parking_id = parking_id) if history_inst.save(): responseData = client.send_message({ 'from': 'Nexmo', 'to': user_inst.hp_number, 'text': 'RM0.00 EzPark: Your car is parked in Mall: [' + mall_inst.outlet + '], at Floor: [' + floor_inst.floor + '], in Parking Bay: [' + parking_inst.parking_num + ']///' }) # if responseData["messages"][0]["status"] == "0": responseObj = { 'status': 'success', 'message': 'Successfully saved your parking!' } return jsonify(responseObj), 200 # else: # responseObj = { # 'status': 'failed', # 'message': 'Message sent failed' # } # return jsonify(responseObj), 400 else: responseObj = { 'status': 'failed', 'message': 'Parking failed to save!' } return jsonify(responseObj), 400