Esempio n. 1
0
def lambda_handler(event, context):
    # TODO implement
    dynamodb = boto3.resource("dynamodb")

    print(event)
    if event['queryStringParameters']['userID']:
        userId = event['queryStringParameters']['userID']
        attributes_to_get = ['userId', 'groupId']
        entry = scan_dynamo([userId], "persons", attributes_to_get, "personId")
        if entry:
            groups = entry[0]['groupId']
            attributes_to_get = ["documentIds"]
            docIds = scan_dynamo(groups, "groups", attributes_to_get, "groupId")
            docIds = [f["documentIds"] for f in docIds]
            docIds = list(set(list(chain(*docIds))))
            print(docIds)
        else:
            docIds = {}

    elif event['queryStringParameters']['groupID']:
        groupId = event['queryStringParameters']['groupID']
        attributes_to_get = ['documentIds']
        entry = scan_dynamo([groupId], "groups", attributes_to_get, "groupId")
        if entry:
            docIds = entry[0]['documentIds']
        else:
            docIds = []
        print(docIds)

    if docIds:
        docTable = dynamodb.Table("documents")
        attributes_to_get = ['documentId', 'name', 'description']
        documents = scan_dynamo(docIds, "documents", attributes_to_get, "documentId")
    else:
        documents = []

    return {
        'statusCode': 200,
        'body': json.dumps(documents),
        'headers': {
            "Access-Control-Allow-Origin": "*",
        }
    }
Esempio n. 2
0
def getAccessIds(userId):
    attributes_to_get = ['personId', 'groupId']
    entry = scan_dynamo([userId], "persons", attributes_to_get, "personId")
    groups = entry[0]['groupId']
    print(groups)
    if not groups:
        return [], []

    attributes_to_get = ['documentIds']
    entry = scan_dynamo(groups, "groups", attributes_to_get, "groupId")
    print(entry)
    docIdListofLists = [doc['documentIds'] for doc in entry]
    docIds = [docId for sublist in docIdListofLists for docId in sublist]
    print("Document Ids: ", docIds)
    if not docIds:
        return [], []
    attributes_to_get = ['pageIds']
    entry = scan_dynamo(docIds, "documents", attributes_to_get, "documentId")
    pageIdListofLists = [page['pageIds'] for page in entry]
    pageIds = [pageId for sublist in pageIdListofLists for pageId in sublist]
    print("PageIds: ", pageIds)

    return docIds, pageIds
def lambda_handler(event, context):
    pageId = event['queryStringParameters']['q']
    dynamodb = boto3.resource("dynamodb")
    docTable = dynamodb.Table("comments")
    attributes_to_get = ['comment', 'time', 'userId']
    comment_val = scan_dynamo([pageId], "comments", attributes_to_get,
                              "pageId")

    peopleTable = dynamodb.Table('persons')
    for entry in comment_val:
        person = peopleTable.get_item(Key={"personId": entry['userId']})
        entry['userName'] = person['Item']['name']

    comment_val.sort(key=lambda x: x['time'], reverse=False)

    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps(comment_val),
        'headers': {
            "Access-Control-Allow-Origin": "*",
        }
    }
Esempio n. 4
0
def checkIfExist(personId):
    persons = scan_dynamo([personId], 'persons', ['personId'], 'personId')
    if persons:
        return True
    return False