Skip to content

Commit

Permalink
change DELETE rating & skill separator
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-mba committed Jan 2, 2024
1 parent 99ea87c commit 73656ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,23 @@ GET /Skills - Get all skills<br>
GET /Skills/{rating} = Get skill with specified rating<br>

POST /Skills - Add skill
```json
```js
body: {
"rating": "rating Integer",
"skill": "skill String"
}
```

PUT /Skills - Update skill rating
```json
```js
body: {
"oldrating": "current rating Integer",
"newrating": "new rating Integer",
"skill": "skill String"
}
```

DELETE /Skills/{skill_id} - Delete selected skill
```js
//Skill ID is rating & skill separated by the hash character
//In JavaScript
skill_id = encodeURIComponent(`${rating}#${skill}`)

```
```python
#In Python
skill_id = urllib.parse.quote(f"{rating}#{skill}")
```
DELETE /Skills/{rating}/{skill} - Delete selected skill

DELETE /Skills/ALL_SKILLS - Delete all skills

Expand Down
11 changes: 9 additions & 2 deletions dynamodb/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ def lambda_handler(event, context):
name = unquote(name);

if name != 'ALL_SKILLS':
keys = name.split('/')
if len(keys) != 2:
return respond({
'message': 'DELETE required parameter malformed'
})
sk = '#'.join(keys)

try:
table.delete_item(Key={'PK': userid, 'SK': name})
table.delete_item(Key={'PK': userid, 'SK': sk})
response = {'message': 'Skill deleted', 'name': name }

except ClientError as error:
Expand All @@ -39,7 +46,7 @@ def lambda_handler(event, context):
return respond(str(error))

return respond(None, response)

try:
expression = Key('PK').eq(userid)
query_results = table.query(KeyConditionExpression=expression)
Expand Down
2 changes: 1 addition & 1 deletion template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Resources:
Delete:
Type: HttpApi
Properties:
Path: /Skills/{name}
Path: /Skills/{name+}
Method: delete
ApiId: !Ref ApiResource

Expand Down

0 comments on commit 73656ed

Please sign in to comment.