Skip to content

Commit

Permalink
Use model for public org details in public list endpoint
Browse files Browse the repository at this point in the history
This will be more easily extensible if we want to add additional
fields (like an organization description) that would be visible in
a public profile.
  • Loading branch information
tw4l committed Nov 25, 2024
1 parent beab346 commit 15b66f7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion backend/btrixcloud/colls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
SuccessResponse,
CollectionSearchValuesResponse,
OrgPublicCollections,
PublicOrgDetails,
CollAccessType,
)
from .utils import dt_now
Expand Down Expand Up @@ -416,7 +417,9 @@ async def get_org_public_collections(self, org_slug: str):
if not collections:
raise HTTPException(status_code=404, detail="public_collections_not_found")

return OrgPublicCollections(orgName=org.name, collections=collections)
public_org_details = PublicOrgDetails(name=org.name)

return OrgPublicCollections(org=public_org_details, collections=collections)


# ============================================================================
Expand Down
11 changes: 9 additions & 2 deletions backend/btrixcloud/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,13 +1144,20 @@ class RenameOrg(BaseModel):
slug: Optional[str] = None


# ============================================================================
class PublicOrgDetails(BaseModel):
"""Model for org details that are available in public profile"""

name: str


# ============================================================================
class OrgPublicCollections(BaseModel):
"""Model for listing public collections in org"""

orgName: str
org: PublicOrgDetails

collections: List[CollOut]
collections: List[CollOut] = []


# ============================================================================
Expand Down
2 changes: 1 addition & 1 deletion backend/test/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def test_list_public_collections(
r = requests.get(f"{API_PREFIX}/public-collections/{org_slug}")
assert r.status_code == 200
data = r.json()
assert data["orgName"] == org_name
assert data["org"]["name"] == org_name

collections = data["collections"]
assert len(collections) == 2
Expand Down

0 comments on commit 15b66f7

Please sign in to comment.