bagustyo commited on
Commit
37bb233
1 Parent(s): 52d620f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +3 -4
main.py CHANGED
@@ -1,5 +1,5 @@
1
  from fastapi import FastAPI, HTTPException
2
- from pydantic import BaseModel
3
  import random
4
  import string
5
  from datetime import datetime
@@ -19,6 +19,7 @@ if not DB_FILE.exists():
19
  # Data model
20
  class Data(BaseModel):
21
  number: int
 
22
 
23
  # Generate unique ID
24
  def generate_id():
@@ -42,6 +43,7 @@ def add_data(data: Data):
42
  "id": generate_id(),
43
  "date": datetime.utcnow().isoformat(),
44
  "number": data.number,
 
45
  }
46
  database.append(new_entry)
47
  write_database(database)
@@ -55,10 +57,7 @@ def get_data():
55
  @app.get("/data/{item_id}")
56
  def get_data_by_id(item_id: str):
57
  database = read_database()
58
- print(f"Database: {database}") # Debugging: print the database
59
  for entry in database:
60
- print(f"Checking entry: {entry}") # Debugging: print each entry
61
  if entry["id"] == item_id:
62
  return entry
63
  raise HTTPException(status_code=404, detail="Item not found")
64
-
 
1
  from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel, EmailStr
3
  import random
4
  import string
5
  from datetime import datetime
 
19
  # Data model
20
  class Data(BaseModel):
21
  number: int
22
+ email: EmailStr # Add the email field with validation
23
 
24
  # Generate unique ID
25
  def generate_id():
 
43
  "id": generate_id(),
44
  "date": datetime.utcnow().isoformat(),
45
  "number": data.number,
46
+ "email": data.email, # Include the email field
47
  }
48
  database.append(new_entry)
49
  write_database(database)
 
57
  @app.get("/data/{item_id}")
58
  def get_data_by_id(item_id: str):
59
  database = read_database()
 
60
  for entry in database:
 
61
  if entry["id"] == item_id:
62
  return entry
63
  raise HTTPException(status_code=404, detail="Item not found")