From efce742319e1a2c660504700c2f5a375a57d6feb Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sun, 12 Nov 2023 10:25:37 -0500 Subject: [PATCH 1/3] code gardening --- .../Controllers/SummaryItemsController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs b/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs index 741f982d..27465664 100644 --- a/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs +++ b/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs @@ -44,7 +44,7 @@ public async Task UpdateSummaryItem(string user, string owner, string repo) } [HttpPost("UpdateSummaryItemNuGetPackageStats")] - public async Task UpdateSummaryItemNuGetPackageStats(NuGetPayload nugetPayload) + public async Task UpdateSummaryItemNuGetPackageStats(NuGetPayload nugetPayload) { if (nugetPayload != null) { From 5be21d2b24f1be369e33df5dbec62de910cb1e3e Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sun, 12 Nov 2023 11:21:40 -0500 Subject: [PATCH 2/3] code gardening --- src/RepoGovernance.Core/SummaryItemsDA.cs | 3 ++- .../Controllers/SummaryItemsController.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/RepoGovernance.Core/SummaryItemsDA.cs b/src/RepoGovernance.Core/SummaryItemsDA.cs index 5f3a033c..25fb4fc8 100644 --- a/src/RepoGovernance.Core/SummaryItemsDA.cs +++ b/src/RepoGovernance.Core/SummaryItemsDA.cs @@ -404,7 +404,8 @@ public static List GetRepos(string user) ; } - public static async Task UpdateSummaryItemNuGetPackageStats(string? connectionString, + public static async Task UpdateSummaryItemNuGetPackageStats( + string? connectionString, string user, string owner, string repo, diff --git a/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs b/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs index 27465664..ad2f5bc0 100644 --- a/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs +++ b/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs @@ -54,7 +54,7 @@ public async Task UpdateSummaryItemNuGetPackageStats(NuGetPayload nugetPayl string? jsonPayload = nugetPayload?.JsonPayload; string? payloadType = nugetPayload?.PayloadType; - if (repo == null || owner == null || user == null || jsonPayload == null) + if (repo == null || owner == null || user == null || jsonPayload == null || payloadType == null) { return -1; } From 37d27d40bfbb9787be1c9cc39910f5e3ac032daf Mon Sep 17 00:00:00 2001 From: Sam Smith Date: Sun, 12 Nov 2023 12:35:17 -0500 Subject: [PATCH 3/3] Updates to capture the value correctly --- .../Controllers/SummaryItemsController.cs | 3 +- .../Models/NuGetPayload.cs | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs b/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs index ad2f5bc0..0501bbe8 100644 --- a/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs +++ b/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs @@ -51,7 +51,8 @@ public async Task UpdateSummaryItemNuGetPackageStats(NuGetPayload nugetPayl string? repo = nugetPayload?.Repo; string? owner = nugetPayload?.Owner; string? user = nugetPayload?.User; - string? jsonPayload = nugetPayload?.JsonPayload; + //There is some weirdness when the json is embedded in this object and then the object is serialized a second time - it returns an array of strings. + string? jsonPayload = nugetPayload?.JsonPayloadString; string? payloadType = nugetPayload?.PayloadType; if (repo == null || owner == null || user == null || jsonPayload == null || payloadType == null) diff --git a/src/RepoGovernance.Service/Models/NuGetPayload.cs b/src/RepoGovernance.Service/Models/NuGetPayload.cs index 143d12c8..907c89ee 100644 --- a/src/RepoGovernance.Service/Models/NuGetPayload.cs +++ b/src/RepoGovernance.Service/Models/NuGetPayload.cs @@ -1,8 +1,10 @@ -namespace RepoGovernance.Service.Models +using System.Text; + +namespace RepoGovernance.Service.Models { public class NuGetPayload { - public NuGetPayload(string user, string owner, string repo, string jsonPayload, string payloadType) + public NuGetPayload(string user, string owner, string repo, string[] jsonPayload, string payloadType) { User = user; Owner = owner; @@ -13,7 +15,29 @@ public NuGetPayload(string user, string owner, string repo, string jsonPayload, public string? User { get; set; } public string? Owner { get; set; } public string? Repo { get; set; } - public string? JsonPayload { get; set; } + //There is some weirdness when the json is embedded in this object and then the object is serialized a second time - it returns an array of strings. + public string[]? JsonPayload { get; set; } + public string JsonPayloadString + { + get + { + if (JsonPayload == null) + { + return string.Empty; + } + return UsingLoopStringBuilder(JsonPayload); + } + } public string? PayloadType { get; set; } + + private string UsingLoopStringBuilder(string[] array) + { + StringBuilder result = new(); + foreach (string item in array) + { + result.Append(item); + } + return result.ToString(); + } } }