Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
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
6 changes: 6 additions & 0 deletions backend/apps/api/rest/v0/chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ class ChapterDetail(ChapterBase):
"""Detail schema for Chapter (used in single item endpoints)."""

country: str
leaders: list[str]
region: str

@staticmethod
def resolve_leaders(obj):
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are technically leader names (not leader objects).
I'm not sure how to handle compound objects within API yet (add minimum data + a separate endpoint vs adding all data).

Copy link
Collaborator Author

@rudransh-shrivastava rudransh-shrivastava Nov 23, 2025

Choose a reason for hiding this comment

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

Yeah, I'll update it to leader_names for now. But I think it's wrong to name it leader_names. What do I do?

I found Stripe API Docs / Expand interesting.

The API has an Expand feature that allows you to retrieve linked objects in a single call, effectively replacing the object ID with all its properties and values. For example, say you wanted to access details on a customer tied to a given Checkout Session. You would retrieve the Checkout Session and pass the customer property to the expand array, which tells Stripe to include the entire Customer object in the response

Copy link
Collaborator Author

@rudransh-shrivastava rudransh-shrivastava Nov 23, 2025

Choose a reason for hiding this comment

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

I'm not sure how to implement this, but I can look into it if we go down this path :)

"""Resolve leaders."""
return [leader.member_name for leader in obj.entity_leaders]


class ChapterError(Schema):
"""Chapter error schema."""
Expand Down
6 changes: 6 additions & 0 deletions backend/apps/api/rest/v0/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class ProjectDetail(ProjectBase):
"""Detail schema for Project (used in single item endpoints)."""

description: str
leaders: list[str]

@staticmethod
def resolve_leaders(obj):
"""Resolve leaders."""
return [leader.member_name for leader in obj.entity_leaders]


class ProjectError(Schema):
Expand Down
6 changes: 6 additions & 0 deletions backend/tests/apps/api/rest/v0/chapter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@
],
)
def test_chapter_serializer_validation(chapter_data):
class MockEntityMember:
def __init__(self, name):
self.member_name = name

class MockChapter:
def __init__(self, data):
for key, value in data.items():
setattr(self, key, value)
self.nest_key = data["key"]
self.entity_leaders = [MockEntityMember("Alice"), MockEntityMember("Bob")]

chapter = ChapterDetail.from_orm(MockChapter(chapter_data))

Expand All @@ -44,6 +49,7 @@ def __init__(self, data):
assert chapter.key == chapter_data["key"]
assert chapter.latitude == chapter_data["latitude"]
assert chapter.longitude == chapter_data["longitude"]
assert chapter.leaders == ["Alice", "Bob"]
assert chapter.name == chapter_data["name"]
assert chapter.region == chapter_data["region"]
assert chapter.updated_at == datetime.fromisoformat(chapter_data["updated_at"])
6 changes: 6 additions & 0 deletions backend/tests/apps/api/rest/v0/project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,23 @@
],
)
def test_project_serializer_validation(project_data):
class MockEntityMember:
def __init__(self, name):
self.member_name = name

class MockProject:
def __init__(self, data):
for key, value in data.items():
setattr(self, key, value)
self.nest_key = data["key"]
self.entity_leaders = [MockEntityMember("Alice"), MockEntityMember("Bob")]

project = ProjectDetail.from_orm(MockProject(project_data))

assert project.created_at == datetime.fromisoformat(project_data["created_at"])
assert project.description == project_data["description"]
assert project.key == project_data["key"]
assert project.leaders == ["Alice", "Bob"]
assert project.level == project_data["level"]
assert project.name == project_data["name"]
assert project.updated_at == datetime.fromisoformat(project_data["updated_at"])