From 3795ab0c38a32ab0cf2fef950f590f4a283c111f Mon Sep 17 00:00:00 2001 From: JackDevAU Date: Mon, 11 Dec 2023 17:14:06 +1000 Subject: [PATCH] adds http docs + fixes generate history json --- .../History/GenerateHistoryFileFunction.cs | 3 +- .../Functions/Widget/GetLatestRules.cs | 2 +- SSW.Rules.AzFuncs/helpers/Utils.cs | 18 ++++++++++ docs/Functions/Functions.http | 35 +++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 docs/Functions/Functions.http diff --git a/SSW.Rules.AzFuncs/Functions/History/GenerateHistoryFileFunction.cs b/SSW.Rules.AzFuncs/Functions/History/GenerateHistoryFileFunction.cs index a04c522..0134e88 100644 --- a/SSW.Rules.AzFuncs/Functions/History/GenerateHistoryFileFunction.cs +++ b/SSW.Rules.AzFuncs/Functions/History/GenerateHistoryFileFunction.cs @@ -38,7 +38,6 @@ public async Task Run( })); var responseMessage = JsonConvert.SerializeObject(ruleHistory); - - return req.CreateJsonResponse(responseMessage); + return await req.SendJsonResponse(responseMessage); } } \ No newline at end of file diff --git a/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs b/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs index 3d87483..7685c27 100644 --- a/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs +++ b/SSW.Rules.AzFuncs/Functions/Widget/GetLatestRules.cs @@ -34,7 +34,7 @@ public async Task Run( var filteredRulesList = filteredRules.ToList(); return filteredRulesList.Count == 0 - ? req.CreateJsonErrorResponse(HttpStatusCode.NotFound) + ? req.CreateJsonErrorResponse(HttpStatusCode.NotFound, "Not Found") : req.CreateJsonResponse(filteredRules); } } \ No newline at end of file diff --git a/SSW.Rules.AzFuncs/helpers/Utils.cs b/SSW.Rules.AzFuncs/helpers/Utils.cs index aa0a827..ce77810 100644 --- a/SSW.Rules.AzFuncs/helpers/Utils.cs +++ b/SSW.Rules.AzFuncs/helpers/Utils.cs @@ -57,6 +57,24 @@ public static HttpResponseData CreateJsonResponse(this HttpRequestData req, obje return response; } + + /// + /// Create a JSON object response + /// + /// + /// Default 200 + /// Default empty + /// + public static async Task SendJsonResponse(this HttpRequestData req, string message, HttpStatusCode statusCode = HttpStatusCode.OK) + { + + var response = req.CreateResponse(statusCode); + response.Headers.Add("Content-Type", "application/json"); + response.StatusCode = statusCode; + await response.WriteStringAsync(message); + return response; + } + public static async Task ReadFormDataAsync(this HttpRequestData req) { using var reader = new StreamReader(req.Body); diff --git a/docs/Functions/Functions.http b/docs/Functions/Functions.http new file mode 100644 index 0000000..ec70da1 --- /dev/null +++ b/docs/Functions/Functions.http @@ -0,0 +1,35 @@ +@BaseApiUrl = http://localhost:7071/api + +# Health +GET {{BaseApiUrl}}/HealthCheckFunction +Content-Type: application/json + +### +# History - Generate +GET {{BaseApiUrl}}/GenerateHistoryFileFunction +Content-Type: application/json + +### +# History - SyncCommitHash +GET {{BaseApiUrl}}/GetHistorySyncCommitHash +Content-Type: application/json + + +### +# Widget - Get LatestRules (with GitHub) +@skip = 0 +@take = 10 +@githubUsername = "" + +GET {{BaseApiUrl}}/GetLatestRules?skip={{skip}}&take={{take}}&githubUsername={{githubUsername}} +Content-Type: application/json + +### +# Widget - Get LatestRules (No GitHub) + +GET {{BaseApiUrl}}/GetLatestRules?skip={{skip}}&take={{take}} +Content-Type: application/json + + +### +# Widget - Update LatestRules