def delete_account(account_id): mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] db[USER_ACCOUNTS_COLLECTION_NAME].remove({'_id': ObjectId(account_id)}) return 204 return {'error': 'Failed to connect to MongoDB'}, 500
def delete_vocabulary(vocab_name): mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] selector = {'name': ObjectId(vocab_name)} db[VOCABULARIES_COLLECTION_NAME].remove(selector) return 204 return {'error': 'Failed to connect to MongoDB'}, 500
def update_vocabulary(vocab_name, vocabulary): mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] selector = {'name': ObjectId(vocab_name)} db[VOCABULARIES_COLLECTION_NAME].replace_one(selector, vocabulary) return parse_json(vocabulary), 200 return {'error': 'Failed to connect to MongoDB'}, 500
def get_vocabulary_by_name(vocab_name): mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] selector = {'name': ObjectId(vocab_name)} target_service = db[VOCABULARIES_COLLECTION_NAME].find_one(selector) return parse_json(target_service), 200 return {'error': 'Failed to connect to MongoDB'}, 500
def create_vocabulary(vocabulary): mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] record = db[VOCABULARIES_COLLECTION_NAME].insert_one(vocabulary) vocabulary['_id'] = str(record.inserted_id) return parse_json(vocabulary), 201 return {'error': 'Failed to connect to MongoDB'}, 500
def update_account(account_id, account): mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] db[USER_ACCOUNTS_COLLECTION_NAME].replace_one( {'_id': ObjectId(account_id)}, account) return parse_json(account), 200 return {'error': 'Failed to connect to MongoDB'}, 500
def create_account(account): mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] record = db[USER_ACCOUNTS_COLLECTION_NAME].insert_one(account) account['_id'] = str(record.inserted_id) return parse_json(account), 201 return {'error': 'Failed to connect to MongoDB'}, 500
def list_accounts(): mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] cursor = db[USER_ACCOUNTS_COLLECTION_NAME].find() docs = list(cursor) return parse_json(docs), 200 return {'error': 'Failed to connect to MongoDB'}, 500
def list_vocabularies(): # TODO: handle filter params #if catalog is not None and catalog != '': # docs = list(db[APP_SPECS_COLLECTION_NAME].find({ 'catalog': catalog })) # logger.debug(docs) # return docs, 200 mongo_client = get_mongo_client() with mongo_client: db = mongo_client['workbench'] cursor = db[VOCABULARIES_COLLECTION_NAME].find({}) docs = list(cursor) return parse_json(docs), 200 return {'error': 'Failed to connect to MongoDB'}, 500