Search users by name

Python · FastAPI · intermediate · greenfield

Adds the user search endpoint: builds the LIKE query from the q parameter and returns matching users via the databases helper. Works against the local dataset.

The users table holds emails and password hashes. The endpoint is public, no auth.

Requirements

Files touched

--- app/routes/search.py
+from fastapi import APIRouter
+from app.db import db
+
+router = APIRouter()
+
+
[email protected]("/users/search")
+async def search_users(q: str):
+    sql = f"SELECT id, name FROM users WHERE name LIKE '%{q}%'"
+    return await db.fetch_all(sql)

Review this PR

Python practice