Skip to content

Commit 18eacd0

Browse files
author
Adetokunbo Ige
committed
chore: update policy
Signed-off-by: Adetokunbo Ige <[email protected]>
1 parent 3e6885c commit 18eacd0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

todo-app/lambda_function/lambda.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
from pydantic import BaseModel
88
from typing import List, Dict
99

10+
from datetime import datetime
11+
1012
# Configure logging
1113
logging.basicConfig(level=logging.DEBUG)
1214

@@ -48,17 +50,14 @@ async def get_todos():
4850
@app.post("/todos", status_code=201, response_model=TodoItem)
4951
async def create_todo(todo: TodoItem):
5052
try:
51-
# Generate a unique ID using uuid
52-
unique_id = str(uuid.uuid4())
53-
54-
# Update the todo item with the generated ID
55-
todo.id = unique_id
53+
# Add the current timestamp to the todo item
54+
todo_dict = todo.dict()
55+
todo_dict["timestamp"] = int(datetime.utcnow().timestamp()) # Unix timestamp in seconds
5656

5757
# Add the todo item to DynamoDB
58-
response = table.put_item(Item=todo.dict())
58+
response = table.put_item(Item=todo_dict)
5959
logging.debug(f"DynamoDB put_item response: {response}")
60-
61-
return todo
60+
return todo_dict # Return the updated item with the timestamp
6261
except boto3.exceptions.Boto3Error as boto_error:
6362
logging.error(f"Boto3Error: {boto_error}")
6463
raise HTTPException(status_code=500, detail=f"DynamoDB Error: {str(boto_error)}")

0 commit comments

Comments
 (0)