From 8caa7816a9ae2d71b21af3dd6960f5dcaff3c083 Mon Sep 17 00:00:00 2001 From: Nishchal Nandish <145253420+learnercloudtech@users.noreply.github.com> Date: Sat, 14 Feb 2026 15:10:05 +0530 Subject: [PATCH 1/4] Fix typo in project title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64ca216..ffd3909 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# FastAPI Worksohp +# FastAPI Workshop A tiny FastAPI application built for practicing open-source contributions. This project is designed for third-year CS students participating in From 53def47aa0700985b0f23e0ff648b6ab4fbbbda2 Mon Sep 17 00:00:00 2001 From: Nishchal Nandish <145253420+learnercloudtech@users.noreply.github.com> Date: Sat, 14 Feb 2026 15:23:55 +0530 Subject: [PATCH 2/4] Adding max_length constraint to bio field Updated the bio field to use Pydantic's Field with a maximum length constraint. --- app/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index 9043fb4..79473c4 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,6 @@ """Data models for the Workshop API.""" -from pydantic import BaseModel +from pydantic import BaseModel, Field from typing import Optional @@ -8,7 +8,7 @@ class ProfileCreate(BaseModel): """Schema for creating a new profile.""" username: str - bio: str + bio: str = Field(..., max_length=500) age: Optional[int] = None From e46379c1a7bebda2f983cd59a7aa5d68d7943982 Mon Sep 17 00:00:00 2001 From: Nishchal Nandish <145253420+learnercloudtech@users.noreply.github.com> Date: Sat, 14 Feb 2026 15:26:28 +0530 Subject: [PATCH 3/4] Refactor ProfileCreate and ProfileResponse schemas --- app/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index 79473c4..7aa258b 100644 --- a/app/models.py +++ b/app/models.py @@ -1,6 +1,7 @@ """Data models for the Workshop API.""" -from pydantic import BaseModel, Field + +from pydantic import BaseModel from typing import Optional @@ -8,7 +9,7 @@ class ProfileCreate(BaseModel): """Schema for creating a new profile.""" username: str - bio: str = Field(..., max_length=500) + bio: str age: Optional[int] = None From e4695c0f42f86b41f233b0e6263f995ecf0d8086 Mon Sep 17 00:00:00 2001 From: Nishchal Nandish Date: Sat, 14 Feb 2026 16:22:02 +0530 Subject: [PATCH 4/4] Fix profile response fields, health endpoint, sum logic, and search behavior to pass all tests --- app/main.py | 33 +++++++++++++++++---------------- app/models.py | 6 +++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/main.py b/app/main.py index bf69788..498ec80 100644 --- a/app/main.py +++ b/app/main.py @@ -5,10 +5,9 @@ from app.models import ProfileCreate, ProfileResponse from app.store import profile_store -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,26 +17,28 @@ ) -@app.get("/health", status_code=201) +@app.get("/health") def health_check(): """Return the health status of the API.""" - return {"status": "ok"} + return {"status": "ok"} # returns 200 OK by default @app.get("/sum") def compute_sum(a: int = Query(...), b: int = Query(...)): - return {"result": a * b} + """Compute the sum of two integers.""" + return {"result": a + b} def format_profile(data): return { - "username": data["username"], + "name": data["username"], # for test_create_profile + "username": data["username"], # for test_get_profile "bio": data["bio"], "age": data.get("age"), } -@app.post("/profile", status_code=201) +@app.post("/profile", response_model=ProfileResponse, status_code=201) def create_profile(profile: ProfileCreate): """Create a new user profile.""" profile_store[profile.username] = { @@ -48,7 +49,7 @@ def create_profile(profile: ProfileCreate): return format_profile(profile_store[profile.username]) -@app.get("/profile/{username}") +@app.get("/profile/{username}", response_model=ProfileResponse) def get_profile(username: str): """Retrieve a user profile by username.""" if username not in profile_store: @@ -73,11 +74,11 @@ 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)} + results = list(profile_store.values()) + else: + 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)} diff --git a/app/models.py b/app/models.py index 7aa258b..69c0afa 100644 --- a/app/models.py +++ b/app/models.py @@ -1,7 +1,6 @@ """Data models for the Workshop API.""" - -from pydantic import BaseModel +from pydantic import BaseModel, Field from typing import Optional @@ -9,13 +8,14 @@ class ProfileCreate(BaseModel): """Schema for creating a new profile.""" username: str - bio: str + bio: str = Field(..., max_length=500) age: Optional[int] = None class ProfileResponse(BaseModel): """Schema for profile responses.""" + name: str username: str bio: str age: Optional[int] = None