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 741f982d..0501bbe8 100644 --- a/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs +++ b/src/RepoGovernance.Service/Controllers/SummaryItemsController.cs @@ -44,17 +44,18 @@ 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) { 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) + if (repo == null || owner == null || user == null || jsonPayload == null || payloadType == null) { return -1; } 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(); + } } }