-
Notifications
You must be signed in to change notification settings - Fork 0
Remove inline root, health, and echo routes #11
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,47 +22,3 @@ | |
| router.include_router(health_router) | ||
| router.include_router(echo_router) | ||
|
Comment on lines
21
to
23
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| @router.get("/") | ||
| def root(conn=Depends(get_db_connection)) -> dict: | ||
| """Return a structured welcome message for the API root, including product data.""" | ||
| cur = conn.cursor() | ||
| try: | ||
| cur.execute('SELECT id, name, description, price, in_stock, created_at FROM product;') | ||
| products = [ | ||
| { | ||
| "id": row[0], | ||
| "name": row[1], | ||
| "description": row[2], | ||
| "price": str(row[3]) if row[3] is not None else None, | ||
| "in_stock": row[4], | ||
| "created_at": row[5].isoformat() if row[5] else None, | ||
| } | ||
| for row in cur.fetchall() | ||
| ] | ||
| finally: | ||
| cur.close() | ||
| epoch = int(time.time() * 1000) | ||
| meta = { | ||
| "version": __version__, | ||
| "time": time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), | ||
| "epoch": epoch, | ||
| "severity": "success", | ||
| "message": f"NX AI says hello. Returned {len(products)} products.", | ||
| } | ||
| return {"meta": meta, "data": products} | ||
|
|
||
|
|
||
| @router.get("/health") | ||
| def health() -> dict[str, str]: | ||
| """Return the health status of the application.""" | ||
| return {"status": "ok"} | ||
|
|
||
|
|
||
| @router.post("/echo", response_model=EchoResponse) | ||
| def echo(body: EchoRequest) -> EchoResponse: | ||
| """Echo the provided message back to the caller.""" | ||
| return EchoResponse(echo=body.message) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the inline
GET /handler changes runtime behavior to the implementation inapp/api/root.py, which differs from the deleted one: it opens a new psycopg2 connection directly (bypassingget_db_connection's guaranteed cleanup), doesn’t close the cursor/connection in afinally, and castspricetofloatwithout a None-check (the removed handler returnedNonewhenrow[3]is null and stringified non-null prices). To avoid a behavior regression and potential connection leaks, update the centralized root router to use the existingget_db_connectiondependency and preserve the previous response shape/type handling (including safe cleanup on errors).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback