Skip to content
Merged
Changes from 1 commit
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
44 changes: 0 additions & 44 deletions app/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,3 @@
router.include_router(health_router)
router.include_router(echo_router)
Comment on lines 21 to 23
Copy link

Copilot AI Mar 19, 2026

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 in app/api/root.py, which differs from the deleted one: it opens a new psycopg2 connection directly (bypassing get_db_connection's guaranteed cleanup), doesn’t close the cursor/connection in a finally, and casts price to float without a None-check (the removed handler returned None when row[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 existing get_db_connection dependency and preserve the previous response shape/type handling (including safe cleanup on errors).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

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

Comment on lines 21 to 23
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After deleting the local route handlers, this module now appears to only build an APIRouter and include root_router, health_router, and echo_router. The remaining imports (__version__, os, time, psycopg2, load_dotenv, Depends, get_db_connection, EchoRequest, EchoResponse) are unused and may fail linting/CI; please remove them (and any now-unnecessary side-effect imports) to keep the module minimal.

Copilot uses AI. Check for mistakes.





@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)
Loading