🐛 fix(store.py): remove unnecessary blank line to improve code readability
🐛 fix(service.py): fix incorrect variable name in get_component_likes_count method 🐛 fix(service.py): convert likes count to integer to handle unexpected string values 🐛 fix(service.py): convert component_id to string before sending it in the request payload
This commit is contained in:
parent
d8c133b5d2
commit
787a725207
2 changed files with 11 additions and 2 deletions
|
|
@ -202,6 +202,7 @@ def like_component(
|
|||
likes_count = store_service.get_component_likes_count(
|
||||
store_api_Key, component_id
|
||||
)
|
||||
|
||||
return UsersLikesResponse(likes_count=likes_count, liked_by_user=result)
|
||||
except Exception as exc:
|
||||
raise HTTPException(status_code=500, detail=str(exc))
|
||||
|
|
|
|||
|
|
@ -317,7 +317,13 @@ class StoreService(Service):
|
|||
result = self._get(url, api_key, params)
|
||||
if len(result) == 0:
|
||||
raise ValueError("Component not found")
|
||||
likes = result[0]["liked_by_count"]
|
||||
likes = result["liked_by_count"]
|
||||
# likes_by_count is a string
|
||||
# try to convert it to int
|
||||
try:
|
||||
likes = int(likes)
|
||||
except ValueError:
|
||||
raise ValueError(f"Unexpected value for likes count: {likes}")
|
||||
return likes
|
||||
|
||||
def like_component(self, api_key: str, component_id: str) -> bool:
|
||||
|
|
@ -325,7 +331,9 @@ class StoreService(Service):
|
|||
# if it returns an int, it means the like was removed
|
||||
headers = {"Authorization": f"Bearer {api_key}"}
|
||||
response = httpx.post(
|
||||
self.like_webhook_url, json={"component_id": component_id}, headers=headers
|
||||
self.like_webhook_url,
|
||||
json={"component_id": str(component_id)},
|
||||
headers=headers,
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue