Skip to content

Commit

Permalink
Compute company profile pic url on the schema
Browse files Browse the repository at this point in the history
  • Loading branch information
shri committed Aug 27, 2024
1 parent 700ec1a commit a00a1a7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/app/domain/companies/controllers/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ async def get_company(
) -> Company:
"""Get details about a comapny."""
db_obj = await companies_service.get(company_id)
return companies_service.to_schema(schema_type=Company, data=db_obj)
# company = companies_service.to_schema(schema_type=Company, data=db_obj)
# Workaround due to https://github.com/jcrist/msgspec/issues/673
return Company.from_dict(db_obj.to_dict())

@patch(
operation_id="UpdateCompany",
Expand Down
14 changes: 4 additions & 10 deletions src/app/domain/companies/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,10 @@ class Company(CamelizedBaseStruct):
last_funding: Funding | None = None
org_size: OrgSize | None = None

@classmethod
def from_dict(cls, data):
"""Create an instance from a dictionary."""
obj = cls(**data)

# Add company logo URL
if obj.url:
obj.profile_pic_url = get_logo_dev_link(obj.url)

return obj
def __post_init__(self):
"""Build a profile pic url from company url."""
if self.url:
self.profile_pic_url = get_logo_dev_link(self.url)


class CompanyCreate(CamelizedBaseStruct):
Expand Down
4 changes: 1 addition & 3 deletions src/app/domain/companies/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
from msgspec import Struct
from sqlalchemy.orm import InstrumentedAttribute

__all__ = (
"CompanyService",
)
__all__ = ("CompanyService",)


class CompanyService(SQLAlchemyAsyncRepositoryService[Company]):
Expand Down
2 changes: 1 addition & 1 deletion src/app/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ def get_logo_dev_link(url: str) -> str | None:
logo_dev_token = os.environ["LOGO_DEV_TOKEN"]
return f"https://img.logo.dev/{domain}?token={logo_dev_token}"
except Exception:
pass
return None

0 comments on commit a00a1a7

Please sign in to comment.