Skip to content

Commit

Permalink
Build company profile url on response
Browse files Browse the repository at this point in the history
  • Loading branch information
shri committed Aug 27, 2024
1 parent fe3ea7f commit 3c02187
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/app/domain/companies/controllers/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ async def list_companies(
)
# Workaround due to https://github.com/jcrist/msgspec/issues/673
for company in paginated_response.items:
company.profile_pic_url = get_logo_dev_link(company.url)
if company.url:
company.profile_pic_url = get_logo_dev_link(company.url)

return paginated_response

@post(
Expand Down Expand Up @@ -93,8 +95,11 @@ async def get_company(
"""Get details about a comapny."""
db_obj = await companies_service.get(company_id)
company = companies_service.to_schema(schema_type=Company, data=db_obj)

# Workaround due to https://github.com/jcrist/msgspec/issues/673
company.profile_pic_url = get_logo_dev_link(company.url)
if company.url:
company.profile_pic_url = get_logo_dev_link(company.url)

return company

@patch(
Expand Down
20 changes: 18 additions & 2 deletions src/app/domain/opportunities/controllers/opportunities.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from litestar.exceptions import ValidationException

from app.config import constants
from app.lib.utils import get_logo_dev_link
from app.db.models import User as UserModel
from app.domain.accounts.guards import requires_active_user
from app.domain.accounts.dependencies import provide_users_service
Expand Down Expand Up @@ -58,7 +59,16 @@ async def list_opportunities(
) -> OffsetPagination[Opportunity]:
"""List opportunities that your account can access.."""
results, total = await opportunities_service.get_opportunities(*filters, tenant_id=current_user.tenant_id)
return opportunities_service.to_schema(data=results, total=total, schema_type=Opportunity, filters=filters)
paginated_response = opportunities_service.to_schema(
data=results, total=total, schema_type=Opportunity, filters=filters
)

# Workaround due to https://github.com/jcrist/msgspec/issues/673
for opportunity in paginated_response.items:
if opportunity.company and opportunity.company.url:
opportunity.company.profile_pic_url = get_logo_dev_link(opportunity.company.url)

return paginated_response

@post(
operation_id="CreateOpportunity",
Expand Down Expand Up @@ -119,7 +129,13 @@ async def get_opportunity(
) -> Opportunity:
"""Get details about a comapny."""
db_obj = await opportunities_service.get_opportunity(opportunity_id, tenant_id=current_user.tenant_id)
return opportunities_service.to_schema(schema_type=Opportunity, data=db_obj)
opportunity = opportunities_service.to_schema(schema_type=Opportunity, data=db_obj)

# Workaround due to https://github.com/jcrist/msgspec/issues/673
if opportunity.company and opportunity.company.url:
opportunity.company.profile_pic_url = get_logo_dev_link(opportunity.company.url)

return opportunity

@patch(
operation_id="UpdateOpportunity",
Expand Down

0 comments on commit 3c02187

Please sign in to comment.