Skip to content

Modified the index.py file #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions index.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ class User(SQLModel, table=True):
secret_name: str
age: Optional[str] = None


engine = create_engine("sqlite:///database.db")
SQLModel.metadata.create_all(engine)
# Create an instance of the API class
app = FastAPI()


# Instance of the class User
my_user = User(id=9,name="Juliet",secret_name="wenoteak",age=22)

@app.get("/")
async def root():
# TODO include the user's name if they are logged in
return {"message": "Hello {}".format("World")}
return {"message": "Hello {name}".format(name=my_user.name)}


@app.post("/user")
Expand All @@ -33,15 +38,21 @@ async def create_new_user(*, user: User):
session.add(user)
session.commit()
# TODO return the User ID
return {"message": "User created"}
return my_user.id

# return {"message": "User created"}

@app.get("/user/{id}")
async def get_user(id: int):
with Session(engine) as session:
# TODO return the user based on the ID (and an error if not)
# I will first create an if statement that check if the id of the
# user is equal to the id we have else return an error if it doesnt exist
statement = select(User).where(User.name == id)
user = session.exec(statement).first()
return {"user": user}
if statement:
return {"user": User.name}
else:
return "User not found"

@app.get("/api/webhooks")
async def handle_hook(*, event: Any):
Expand Down