in api/wheel_participant.py [0:0]
def update_participant(event):
"""
Update a participant's name and/or url
:param event: Lambda event containing the API Gateway request body including updated name or url and the
path parameters wheel_id and participant_id
{
"pathParameters":
{
"wheel_id": string ID of the wheel (DDB Hash Key)
"participant_id": string ID of the participant (DDB Hash Key)
},
"body":
{
"id": string ID of the participant (DDB Hash Key),
"name": string name of the wheel (optional),
"url: Valid URL for the participant (optional),
}
}
:return: response dictionary containing the updated participant object if successful
{
"body":
{
"id": string ID of the participant (DDB Hash Key),
"wheel_id": string ID of the wheel (DDB Hash Key),
"name": string name of the wheel,
"url: URL for the participant,
"created_at": creation timestamp,
"updated_at": updated timestamp,
}
}
"""
wheel_id = event['pathParameters']['wheel_id']
participant_id = event['pathParameters']['participant_id']
# Check that the participant exists
participant = WheelParticipant.get_existing_item(Key={'id': participant_id, 'wheel_id': wheel_id})
body = event['body']
params = {'updated_at': get_utc_timestamp()}
if not check_string(body.get('name', 'Not Specified')) or not check_string(body.get('url', 'Not Specified')):
raise base.BadRequestError("Participants names and urls must be at least 1 character in length")
if 'name' in body:
params['name'] = body['name']
if 'url' in body:
params['url'] = body['url']
WheelParticipant.update_item(Key={'id': participant_id, 'wheel_id': wheel_id}, **to_update_kwargs(params))
participant.update(params)
return participant