def add_user(name='Sukhiya', username='******', nationality='Indian', age=20, dbIndex=None, **kwargs): dbName = underlyingDatabaseName(dbIndex) middlewareDBName = middlewareDatabaseName(dbIndex) user_id = underlyingDatabaseWrite.add_user(name, username, nationality, age, dbName=dbName) if user_id is not None: user = underlyingDatabaseRead.get_user_by_id(user_id, dbName=dbName) if CRDT_UPDATE: middlewareDatabaseWrite.update_user(user, dbName=middlewareDBName) msg = messageBuild.get_user_update_msg(user) if 'serverNodeIndex' in kwargs: serverNodeIndex = kwargs.get('serverNodeIndex') if serverNodeIndex is not None: server_address = f'http://0.0.0.0:{str(6000+serverNodeIndex)}' + '/testSending' try_internal_comm(server_address, msg)
def add_post(author, creation_time, content, likes=0, dbIndex=None, **kwargs): dbName = underlyingDatabaseName(dbIndex) middlewareDBName = middlewareDatabaseName(dbIndex) post_id = underlyingDatabaseWrite.add_post(author, creation_time, content, likes, dbName=dbName) if CRDT_UPDATE and post_id is not None: post = underlyingDatabaseRead.get_post_by_id(post_id, dbName=dbName) middlewareDatabaseWrite.add_post(username=author, post=post, dbName=middlewareDBName) msg = messageBuild.get_post_updates_msg(author, post, update_type='add') if 'serverNodeIndex' in kwargs: serverNodeIndex = kwargs.get('serverNodeIndex') if serverNodeIndex is not None: server_address = f'http://0.0.0.0:{str(6000+serverNodeIndex)}' + '/testSending' try_internal_comm(server_address, msg) # print('Message : ', msg) return post_id
def remove_follower(username, follower, dbIndex=None, **kwargs): """ username : this user who is being followed follower: username of the person who is clicking the follow button to follow the user with username in first argument """ dbName = underlyingDatabaseName(dbIndex) middlewareDBName = middlewareDatabaseName(dbIndex) updated = underlyingDatabaseWrite.remove_follower(username, follower, dbName=dbIndex) if CRDT_UPDATE and updated: middlewareDatabaseWrite.remove_user_follower(username, follower, dbName=middlewareDBName) msg = messageBuild.get_followers_update_msg(username, follower, update_type='follow') if 'serverNodeIndex' in kwargs: serverNodeIndex = kwargs.get('serverNodeIndex') if serverNodeIndex is not None: server_address = f'http://0.0.0.0:{str(6000+serverNodeIndex)}' + '/testSending' try_internal_comm(server_address, msg)
def update_user_nationality(username, nationality, dbIndex=None, **kwargs): dbName = underlyingDatabaseName(dbIndex) middlewareDBName = middlewareDatabaseName(dbIndex) updated = underlyingDatabaseWrite.update_user_nationality(username, nationality, dbName=dbName) if CRDT_UPDATE and updated: middlewareDatabaseWrite.update_user_nationality( username, nationality, dbName=middlewareDBName) msg = messageBuild.get_nationality_update_msg(username, nationality) if 'serverNodeIndex' in kwargs: serverNodeIndex = kwargs.get('serverNodeIndex') if serverNodeIndex is not None: server_address = f'http://0.0.0.0:{str(6000+serverNodeIndex)}' + '/testSending' try_internal_comm(server_address, msg)
def reduce_post_likes(post_id, username, dbIndex=None, **kwargs): dbName = underlyingDatabaseName(dbIndex) middlewareDBName = middlewareDatabaseName(dbIndex) updated = underlyingDatabaseWrite.reduce_post_likes(post_id, username, dbName=dbName) if CRDT_UPDATE and updated: middlewareDatabaseWrite.remove_liked_post(username, post_id, dbName=middlewareDBName) msg = messageBuild.get_likedposts_updates_msg(post_id, username, update_type='disliked') if 'serverNodeIndex' in kwargs: serverNodeIndex = kwargs.get('serverNodeIndex') if serverNodeIndex is not None: server_address = f'http://0.0.0.0:{str(6000+serverNodeIndex)}' + '/testSending' try_internal_comm(server_address, msg)
def deletePost(post_id, dbIndex=None, **kwargs): dbName = underlyingDatabaseName(dbIndex) middlewareDBName = middlewareDatabaseName(dbIndex) updated = underlyingDatabaseWrite.deletePost(post_id, dbName=dbName) if CRDT_UPDATE and updated: post = underlyingDatabaseRead.get_post_by_id(post_id, dbName=dbName) username = post.author middlewareDatabaseWrite.remove_post(username, post, dbName=middlewareDBName) msg = messageBuild.get_post_updates_msg(author, post, update_type='remove') if 'serverNodeIndex' in kwargs: serverNodeIndex = kwargs.get('serverNodeIndex') if serverNodeIndex is not None: server_address = f'http://0.0.0.0:{str(6000+serverNodeIndex)}' + '/testSending' try_internal_comm(server_address, msg)