diff --git a/app/main.py b/app/main.py index bf69788..46bded2 100644 --- a/app/main.py +++ b/app/main.py @@ -8,7 +8,7 @@ import math -app = FastAPI(title="FastAPI Worksohp", version="0.1.0") +app = FastAPI(title="FastAPI Workshop", version="0.1.0") app.add_middleware( CORSMiddleware, @@ -18,7 +18,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"} @@ -26,12 +26,14 @@ def health_check(): @app.get("/sum") def compute_sum(a: int = Query(...), b: int = Query(...)): - return {"result": a * b} + + return {"result": a + b} def format_profile(data): return { - "username": data["username"], + "name": data["username"], + "username": data["username"], "bio": data["bio"], "age": data.get("age"), } @@ -59,8 +61,9 @@ def get_profile(username: str): @app.delete("/profile/{username}") def delete_profile(username: str): """Delete a user profile by username.""" + if username not in profile_store: - raise HTTPException(status_code=404, detail="User not found") + raise HTTPException(status_code=404, detail="Profile not found") del profile_store[username] return {"deleted": True} @@ -72,12 +75,11 @@ def search_profiles( limit: int = Query(default=10, ge=1), ): """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)} + + return {"results": results[offset : offset + limit], "total": len(results)} \ No newline at end of file