Beispiel #1
0
def delete_person(request: Request):
    person_id = request.matchdict.get('person_id')
    person = Repository_people.person_by_id(person_id)
    if not person:
        msg = "The Person with id '{}' was not found.".format(person_id)
        return Response(status=404, json_body={'error': msg})

    try:
        Repository_people.delete_person(person_id)
        return Response(status=204, body='Person deleted successfully.')
    except:
        return Response(status=400, body='Could not delete Person.')
Beispiel #2
0
def single_person(request: Request):
    person_id = request.matchdict.get('person_id')
    person = Repository_people.person_by_id(person_id)

    if not person:
        msg = "The person with id '{}' was not found.".format(person_id)
        return Response(status=404, json_body={'error:': msg})

    return person
Beispiel #3
0
def interviewed_people(request: Request):
    interviewed = request.matchdict.get('interviewed')
    people = Repository_people.people_interviewed(interviewed, limit=25)
    #people = Repository_people.all_people( limit=25 )

    # if not person:
    #     msg = "The person with id '{}' was not found.".format(person_id)
    #     return Response(status=404,json_body={'error:': msg})
    #
    # return person

    return people
Beispiel #4
0
def update_person(request: Request):
    person_id = request.matchdict.get('person_id')
    person = Repository_people.person_by_id(person_id)

    if not person:
        msg = "The person with id '{}' was not found.".format(person_id)
        return Response(status=404, json_body={'error': msg})

    try:
        person_data = request.json_body
    except:
        return Response(status=400, body='Could not parse your post as JSON.')

    # Validate
    vm = UpdatePersonViewModel(person_data, person_id)  # event_data , event_id
    vm.compute_details()
    if vm.errors:
        return Response(status=400, body=vm.error_msg)

    try:
        Repository_people.update_person(vm.Person)
        return Response(status=204, body='Person updated successfully.')
    except:
        return Response(status=400, body='Could not update person.')
Beispiel #5
0
def create_person(request: Request):
    try:
        person_data = request.json_body
    except:
        return Response(status=400, body='Could not parse your post as JSON.')

    # Validate
    vm = CreatePersonViewModel(person_data)
    vm.compute_details()
    if vm.errors:
        return Response(status=400, body=vm.error_msg)

    try:
        person = Repository_people.add_person(vm.Person)
        return Response(status=201, json_body=person.to_dict())
    except:
        return Response(status=400, body='Could not save person information.')
Beispiel #6
0
def all_people(_):
    # all_headers = dict(request.headers)
    # # v = t["Authorization"]
    #
    #
    # if "Authorization" not in request.headers:
    #     return Response(status=403,body="No auth header")
    #
    # auth_header = all_headers["Authorization"]
    # parts = auth_header.split(':')
    # if len(parts) != 2 or parts[0].strip() != "api-key":
    #     return Response( status=403, body="Invalid auth header" )
    #
    # api_key = parts[1].strip()
    # user = Repository.find_user_by_api_key(api_key)
    # if not user:
    #     return Response( status=403, body="Invalid api-key; no user with this account number" )
    #
    # print("Listing People for {}".format(user.name))

    people = Repository_people.all_people(limit=25)
    return people
Beispiel #7
0
def all_people_csv(_):
    people = Repository_people.all_people(limit=25)
    return people