From 8c9e345e57e1676d5a110e03725ac9ab09eb9829 Mon Sep 17 00:00:00 2001 From: kiruba Date: Sat, 14 Feb 2026 22:35:07 +0530 Subject: [PATCH] =?UTF-8?q?Search=20with=20empty=20query=20returns=20empty?= =?UTF-8?q?=20results=20instead=20of=20all=20profiles=C2=A0#9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/main.py b/app/main.py index dc3dff6..6fb6537 100644 --- a/app/main.py +++ b/app/main.py @@ -17,7 +17,7 @@ ) -@app.get("/health", status_code=201) +@app.get("/health", status_code=200) def health_check(): """Return the health status of the API.""" return {"status": "ok"} @@ -30,7 +30,8 @@ def compute_sum(a: int = Query(...), b: int = Query(...)): def format_profile(data): return { - "username": data["username"], + "name": data["username"], + "username": data["username"], "bio": data["bio"], "age": data.get("age"), } @@ -72,11 +73,14 @@ def search_profiles( ): """Search profiles by username or bio.""" if not q: - return {"results": [], "total": 0} - - results = [ - p - for p in profile_store.values() - if q.lower() in p["username"].lower() or q.lower() in p["bio"].lower() - ] - return {"results": results[offset : offset + limit - 1], "total": len(results)} + # When query is empty, return all profiles + results = list(profile_store.values()) + else: + # Filter profiles by query + results = [ + p + for p in profile_store.values() + if q.lower() in p["username"].lower() or q.lower() in p["bio"].lower() + ] + + return {"results": results[offset : offset + limit], "total": len(results)}