From e9a6eb4124c6193c08726de251c31b52b2c6185b Mon Sep 17 00:00:00 2001 From: supradeep2819 Date: Mon, 8 Jul 2024 16:20:07 +0530 Subject: [PATCH 1/2] feat: Added endpoint for retrieving product recommendations --- core/routes/api.py | 2 ++ core/routes/shopify_api.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 core/routes/shopify_api.py diff --git a/core/routes/api.py b/core/routes/api.py index fca09e6..075d642 100644 --- a/core/routes/api.py +++ b/core/routes/api.py @@ -27,6 +27,7 @@ from core.routes.social_auth import router as social_api_router from core.routes.stream_api import router as stream_api_router from core.routes.workspace_api import router as workspace_api_router +from core.routes.shopify_api import router as shopify_api_router from valmi_app_backend.utils import BearerAuthentication from core.models import User @@ -154,3 +155,4 @@ def list_spaces(request): router.add_router("", prompt_api_router, tags=["prompts"]) router.add_router("", explore_api_router, tags=["explores"]) router.add_router("", connector_api_router, tags=["connectors"]) +router.add_router("", shopify_api_router, tags=["shopify"]) diff --git a/core/routes/shopify_api.py b/core/routes/shopify_api.py new file mode 100644 index 0000000..4f67d8f --- /dev/null +++ b/core/routes/shopify_api.py @@ -0,0 +1,17 @@ +import json +import logging + +from ninja import Router +from pydantic import Json + + +router = Router() + +# Get an instance of a logger +logger = logging.getLogger(__name__) + + +@router.get("/products/{product_id}/recommendations", response={200: Json, 500: Json}) +def get_prompts(request, product_id): + + return json.dumps({"hi": "hello"}) From 304294f395ab2eebdb1b83b68e34a3bb16036844 Mon Sep 17 00:00:00 2001 From: supradeep2819 Date: Mon, 8 Jul 2024 17:00:02 +0530 Subject: [PATCH 2/2] feat: added endpoint for product recommendations --- core/routes/shopify_api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/routes/shopify_api.py b/core/routes/shopify_api.py index 4f67d8f..290c612 100644 --- a/core/routes/shopify_api.py +++ b/core/routes/shopify_api.py @@ -1,9 +1,8 @@ -import json import logging from ninja import Router from pydantic import Json - +import requests router = Router() @@ -11,7 +10,9 @@ logger = logging.getLogger(__name__) -@router.get("/products/{product_id}/recommendations", response={200: Json, 500: Json}) +@router.get("/products/{product_id}/recommendations", response={200: dict, 500: Json}) def get_prompts(request, product_id): - - return json.dumps({"hi": "hello"}) + response = requests.get( + f'https://thebleulabel.myshopify.com/recommendations/products.json?product_id={product_id}&intent=related') + logger.debug(response) + return response.json()