Skip to content

Commit a00f435

Browse files
committed
Added id validation to url update
1 parent 7036865 commit a00f435

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

api.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,11 @@ paths:
293293
requestTemplates:
294294
application/json: { "Fn::Sub": "{\"TableName\": \"${LinkTable}\",\
295295
\"Key\": {\"id\": {\"S\": $input.json('$.id')}}, \
296-
\"ExpressionAttributeNames\": {\"#u\": \"url\", \"#owner\": \"owner\"}, \
297-
\"ExpressionAttributeValues\":{\":u\": {\"S\": $input.json('$.url')}, \":owner\": {\"S\": \"$context.authorizer.claims.email\"}}, \
296+
\"ExpressionAttributeNames\": {\"#u\": \"url\", \"#owner\": \"owner\", \"#id\":\"id\"}, \
297+
\"ExpressionAttributeValues\":{\":u\": {\"S\": $input.json('$.url')}, \":owner\": {\"S\": \"$context.authorizer.claims.email\"}, \":linkId\":{\"S\":\"$input.params().path.linkId\"}}, \
298298
\"UpdateExpression\": \"SET #u = :u\", \
299299
\"ReturnValues\": \"ALL_NEW\", \
300-
\"ConditionExpression\": \"#owner = :owner\"}" }
300+
\"ConditionExpression\": \"#owner = :owner AND #id = :linkId\"}" }
301301
passthroughBehavior: "when_no_templates"
302302
responses:
303303
"200":

templates/app/linkId/put-request.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
{
2-
"TableName": "SlipLink-LinkTable-A2SD9C321JCE",
2+
"TableName": "Shortie",
33
"Key": {
44
"id": {
55
"S": $input.json('$.id')
66
}
77
},
88
"ExpressionAttributeNames": {
99
"#u": "url",
10-
"#owner": "owner"
10+
"#owner": "owner",
11+
"#id":"id"
1112
},
1213
"ExpressionAttributeValues": {
1314
":u": {
1415
"S": $input.json('$.url')
1516
},
1617
":owner": {
17-
"S": "$context.authorizer.claims.email"
18+
19+
},
20+
":linkId": {
21+
"S": "$input.params().path.linkId"
1822
}
1923
},
2024
"UpdateExpression": "SET #u = :u",
2125
"ReturnValues": "ALL_NEW",
22-
"ConditionExpression": "#owner = :owner"
26+
"ConditionExpression": "#owner = :owner AND #id = :linkId"
2327
}

templates/app/post-response-200.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#set($inputRoot = $input.path('$'))
2+
{
3+
"id": "$inputRoot.Attributes.id.S",
4+
"url": "$inputRoot.Attributes.url.S",
5+
"timestamp": "$inputRoot.Attributes.timestamp.S",
6+
"owner": "$inputRoot.Attributes.owner.S"
7+
}

templates/app/post-response-400.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#set($inputRoot = $input.path('$'))
2+
#if($inputRoot.toString().contains("ConditionalCheckFailedException"))
3+
#set($context.responseOverride.status = 200)
4+
{"error": true,"message": "URL link already exists"}
5+
#end

0 commit comments

Comments
 (0)