File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change 7
7
from pydantic import BaseModel
8
8
from typing import List , Dict
9
9
10
+ from datetime import datetime
11
+
10
12
# Configure logging
11
13
logging .basicConfig (level = logging .DEBUG )
12
14
@@ -48,17 +50,14 @@ async def get_todos():
48
50
@app .post ("/todos" , status_code = 201 , response_model = TodoItem )
49
51
async def create_todo (todo : TodoItem ):
50
52
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
56
56
57
57
# Add the todo item to DynamoDB
58
- response = table .put_item (Item = todo . dict () )
58
+ response = table .put_item (Item = todo_dict )
59
59
logging .debug (f"DynamoDB put_item response: { response } " )
60
-
61
- return todo
60
+ return todo_dict # Return the updated item with the timestamp
62
61
except boto3 .exceptions .Boto3Error as boto_error :
63
62
logging .error (f"Boto3Error: { boto_error } " )
64
63
raise HTTPException (status_code = 500 , detail = f"DynamoDB Error: { str (boto_error )} " )
You can’t perform that action at this time.
0 commit comments