diff --git a/groupTasks/groups/shx-manual-fetch-product-pipeline-products/index.json b/groupTasks/groups/shx-manual-fetch-product-pipeline-products/index.json new file mode 100644 index 0000000..87a0eac --- /dev/null +++ b/groupTasks/groups/shx-manual-fetch-product-pipeline-products/index.json @@ -0,0 +1,15 @@ +{ + "category": "Shinnex", + "name": "Produktpipeline aktualisieren", + "globalInputs": [], + "tasks": [ + { + "name": "Produktpipeline aktualisieren", + "onFinish": "next", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "script.py", + "parameters": [] + } + ] +} diff --git a/groupTasks/groups/shx-manual-fetch-product-pipeline-products/script.py b/groupTasks/groups/shx-manual-fetch-product-pipeline-products/script.py new file mode 100644 index 0000000..3ab7972 --- /dev/null +++ b/groupTasks/groups/shx-manual-fetch-product-pipeline-products/script.py @@ -0,0 +1,23 @@ +import sys +import requests + +try: + with open('../../secrets/admin-dashboard-api-key.txt') as f: + adminDashboardApiKey = f.read().strip() # `.strip()` to remove any extra whitespace or newlines +except FileNotFoundError: + sys.exit("Error: API key file not found.") +except Exception as e: + sys.exit(f"Error reading the API key file: {e}") + +try: + res = requests.get("https://devdash.ex.umbach.dev/api/v1/productpipeline/update", + headers={"X-Api-key": adminDashboardApiKey}) + res.raise_for_status() # Raises a HTTPError if the HTTP request returned an unsuccessful status code +except requests.exceptions.HTTPError as http_err: + sys.exit(f"HTTP error occurred: {http_err}") # HTTP error +except requests.exceptions.RequestException as err: + sys.exit(f"Error occurred: {err}") # Other errors +except Exception as e: + sys.exit(f"An unexpected error occurred: {e}") + +print(f"Response text: {res.text}") \ No newline at end of file diff --git a/main b/main index 63927d9..04774a8 100755 Binary files a/main and b/main differ diff --git a/routers/router/api/v1/productpipeline/productpipeline.go b/routers/router/api/v1/productpipeline/productpipeline.go index f656877..8a9f22d 100644 --- a/routers/router/api/v1/productpipeline/productpipeline.go +++ b/routers/router/api/v1/productpipeline/productpipeline.go @@ -310,3 +310,14 @@ func VoteProduct(c *fiber.Ctx) error { return c.SendStatus(fiber.StatusOK) } + +// can be triggered by admin dashboard group task +func GetManualFetchProducts(c *fiber.Ctx) error { + logger.AddSystemLog(rslogger.LogTypeInfo, "Request for manual retrieval of Google Sheet products received") + + if err := FetchGoogleSheets(); err != nil { + return c.SendStatus(fiber.StatusInternalServerError) + } + + return c.SendStatus(fiber.StatusOK) +} diff --git a/routers/router/router.go b/routers/router/router.go index 260d9af..4aade9a 100644 --- a/routers/router/router.go +++ b/routers/router/router.go @@ -94,9 +94,9 @@ func SetupRoutes(app *fiber.App) { cf.Get("/origins", requestAccessValidation, customerfeedback.GetCustomerFeedbackOrigins) pp := v1.Group("/productpipeline") - pp.Get("/", productpipeline.GetProducts) pp.Post("/vote", productpipeline.VoteProduct) + pp.Get("/update", requestAccessValidation, productpipeline.GetManualFetchProducts) app.Static("/", config.Cfg.FolderPaths.PublicStatic) }