Пример #1
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    username = req.route_params.get('username')

    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    user = client.gamifyre.person.find_one({"uname": username})

    return func.HttpResponse(body=str(user), status_code=200)
Пример #2
0
def main(req: func.HttpRequest):

    activity = req.get_json()

    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    insert_one(client, mongo_constants.GAMIFYRE_DB,
               mongo_constants.collections.ACTIVITY, activity)

    return func.HttpResponse(status_code=200)
Пример #3
0
def main(req: func.HttpRequest) -> func.HttpResponse:

    challenge_id = req.route_params.get('challengeId')

    challenge_object_id = ObjectId(challenge_id)

    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    challenge = client.gamifyre.challenge.find_one(
        {"_id": challenge_object_id})

    return func.HttpResponse(body=str(challenge), status_code=200)
Пример #4
0
def main(req: func.HttpRequest):

    person = req.get_json()

    person['teams'] = []
    person['challenges'] = []
    person['activities'] = []

    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    insert_one(client, mongo_constants.GAMIFYRE_DB,
               mongo_constants.collections.PERSON, person)

    return func.HttpResponse(status_code=200)
Пример #5
0
def main(req: func.HttpRequest):

    challenge = req.get_json()

    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    # Get the owner id from the JSON an add "enrolledIndividuals"
    owner_id = challenge["ownerId"]

    # Add the enrolled individual to the JSON in the ObjectId form.
    challenge["enrolledIndiviuals"] = [ObjectId(owner_id)]

    # Insert the challenge
    insert_one(client, mongo_constants.GAMIFYRE_DB,
               mongo_constants.collections.CHALLENGE, challenge)

    return func.HttpResponse(status_code=200)
Пример #6
0
def main(req: func.HttpRequest):

    team = req.get_json()

    if 'members' not in team.keys():
        team["members"] = [team["owner_id"]]

    if 'challeneges' not in team.keys():
        team["challenges"] = []

    if 'activities' not in team.keys():
        team["activities"] = []

    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    insert_one(client, mongo_constants.GAMIFYRE_DB,
               mongo_constants.collections.TEAM, team)

    return func.HttpResponse(status_code=200)
Пример #7
0
def main(req: func.HttpRequest) -> func.HttpResponse:

    person_id, activity_id = process_request(req)

    if not person_id:
        return func.HttpResponse(
            f'Bad request. Missing required query parameter personId',
            status_code=400)
    if not activity_id:
        return func.HttpResponse(
            f'Bad request. Missing required query parameter activityId',
            status_code=400)

    person_object_id = ObjectId(person_id)
    activity_object_id = ObjectId(activity_id)

    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    append_activity_to_person(client, person_object_id, activity_object_id)

    return func.HttpResponse(status_code=200)
Пример #8
0
def main(req: func.HttpRequest) -> func.HttpResponse:

    # Get the challengeId out of the URL
    challenge_id = req.route_params.get('challengeId')

    # Get the special opbject ID type
    # challenge_object_id = ObjectId(challenge_id)

    # Set up the mongo client
    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    # Get all Activites that have a challenge_id = challengeId and add to a JSON
    # object
    json_response = {}
    json_response["activities"] = []
    for record in client.gamifyre.activity.find({"challenge_id":
                                                 challenge_id}):

        json_response["activities"].append(record)

    # Convert activites to JSON format and return it
    return func.HttpResponse(body=dumps(json_response, indent=4),
                             status_code=200)
def main(req: func.HttpRequest) -> func.HttpResponse:

    person_id, challenge_id = process_request(req)

    if not person_id:
        return func.HttpResponse(
            f'Bad request. Missing required query parameter personId',
            status_code=400)
    if not challenge_id:
        return func.HttpResponse(
            f'Bad request. Missing required query parameter challengeId',
            status_code=400)

    logging.info(str((person_id, challenge_id)))

    person_object_id = ObjectId(person_id)
    challenge_object_id = ObjectId(challenge_id)

    client = get_client(os.environ[env_constants.MONGO_CONNECTION_STRING])

    append_challenge_to_person(client, person_object_id, challenge_object_id)
    append_person_to_challenge(client, person_object_id, challenge_object_id)

    return func.HttpResponse(status_code=200)