def unjoin_chow(cls, chow_id, token): db = database.getInstance() client = boto3.client('cognito-idp', region_name='us-east-2') user = client.get_user(AccessToken=token) chow = db.get_item_as_json('Chow', chow_id) chow['joinedUser'] = None chow['joinedName'] = None chow['joinedEmail'] = None success = db.put_item('Chow', chow) return jsonify({"success":success})
def get_joined_chows(cls, token): db = database.getInstance() client = boto3.client('cognito-idp', region_name='us-east-2') user = client.get_user(AccessToken=token) chows = db.scan_as_json_with_criteria('Chow', 'joinedUser', user['Username']) chows = chowutil.remove_soft_delete(chows) chows = chowutil.remove_expired(chows) return jsonify(chows)
def join_chow(cls, chow_id, token): db = database.getInstance() client = boto3.client('cognito-idp', region_name='us-east-2') user = client.get_user(AccessToken=token) chow = db.get_item_as_json('Chow', chow_id) chow['joinedUser'] = user['Username'] chow['joinedName'] = user['UserAttributes'][2]['Value'] #username is stored here chow['joinedEmail'] = user['UserAttributes'][3]['Value'] #email is stored here success = db.put_item('Chow', chow) return jsonify({"success":success})
def myDynamodb(request): # Create table for testing db = database.getInstance() db.create_table('ChowTest') def remove_table(): print('delete table ChowTest') db.delete_table('ChowTest') request.addfinalizer(remove_table) return db
def get_chows(cls, remove_expired=True): db = database.getInstance() chows = db.scan_as_json('Chow') # remove chows that are marked as 'isDeleted' chows = chowutil.remove_soft_delete(chows) if (remove_expired): chows = chowutil.remove_expired(chows) #remove chows that have been "chowed in" on chows = chowutil.remove_joined_users(chows) response = jsonify(chows) return response
def create_chow(cls, chow): db = database.getInstance() success = db.put_item('Chow', chow) response = jsonify({"success": success}) return response
def delete_chow(cls, chow_id): db = database.getInstance() success = db.soft_delete_item('Chow', chow_id) return jsonify({"success":success})
def update_chow(cls, chow_id, chow): db = database.getInstance() chow['id'] = chow_id success = db.put_item('Chow', chow) return jsonify({"success": success, "chow": chow})
def get_chow(cls, chow_id): db = database.getInstance() chow = db.get_item_as_json('Chow', chow_id) response = jsonify(chow) return response
def initialize_local_database(require_db_confirm=False): #map raw_input (python2) to input (python3) try: input = raw_input except NameError: pass tables = ['User', 'Chow'] users = [ { 'fName': 'Snoop', 'lName': 'Dogg' }, { 'fName': 'Dat', 'lName': 'Boi' }, { 'fName': 'Mr', 'lName': 'Raccoon' }, ] chows = [ { 'food': 'Large Pep. Pizza', 'meetLocation': 'Dominos down main', 'meetTime': '2999-02-08T17:55:00', 'lastUpdated': '2018-02-08T17:55:00', 'notes': 'I ordered this for 2 but my buddy bailed on me. We can work out payment later.' }, { 'food': 'Trash', 'meetLocation': 'garbage can behind Franklin Bristow\'s place.', 'meetTime': '1234-02-08T01:55:00', 'lastUpdated': '2018-02-08T01:55:00', 'notes': 'Calling all raccoons, let\'s eat!' }, ] if (require_db_confirm): print('Make sure DynamoDB Local is running continuing!') input("Press Enter to continue...") db = database.getInstance() print('Setting up tables...') for table in tables: #if table already exists - delete it if db.table_exists(table): db.delete_table(table) if db.create_table(table): print('Table:', table, 'was created!') print('Tables were successfully setup!') print('Populating users...') for user in users: db.put_item('User', user) print('Done!') print('Populating chows...') for chow in chows: db.put_item('Chow', chow) print('Done!') print('Local db setup complete!')