Skip to content

Commit

Permalink
Fixed query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalii-bezuhlyi committed Sep 5, 2024
1 parent 5268a86 commit d732fc4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Apps.XTM/Actions/ProjectActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Apps.XTM.Models.Response.Metrics;
using System;
using Apps.XTM.Models.Response.User;
using Apps.XTM.Utils;

namespace Apps.XTM.Actions;

Expand All @@ -25,7 +26,7 @@ public class ProjectActions(InvocationContext invocationContext, IFileManagement
private const int PageSize = 100;

[Action("List projects", Description = "List all projects")]
public async Task<ListProjectsResponse> ListProjects()
public async Task<ListProjectsResponse> ListProjects([ActionParameter] ListProjectsRequest request)
{
var page = 1;
var hasMorePages = true;
Expand All @@ -38,10 +39,16 @@ public async Task<ListProjectsResponse> ListProjects()
{ "page", page.ToString() },
{ "pageSize", PageSize.ToString() }
};

var response = await Client.ExecuteXtmWithJson<List<SimpleProject>?>(ApiEndpoints.Projects,

if (request.Name != null)
{
queryParams.Add("name", request.Name);
}

var endpoint = $"{ApiEndpoints.Projects}?{queryParams.ToQueryString()}";
var response = await Client.ExecuteXtmWithJson<List<SimpleProject>?>(endpoint,
Method.Get,
queryParams,
null,
Creds);

if (response != null && response.Any())
Expand Down
3 changes: 2 additions & 1 deletion Apps.XTM/DataSourceHandlers/ProjectDataHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Apps.XTM.Actions;
using Apps.XTM.Invocables;
using Apps.XTM.Models.Request.Projects;
using Blackbird.Applications.Sdk.Common.Dynamic;
using Blackbird.Applications.Sdk.Common.Invocation;

Expand All @@ -11,7 +12,7 @@ public class ProjectDataHandler(InvocationContext invocationContext)
public async Task<Dictionary<string, string>> GetDataAsync(DataSourceContext context, CancellationToken cancellationToken)
{
var actions = new ProjectActions(InvocationContext, null!);
var response = await actions.ListProjects();
var response = await actions.ListProjects(new ListProjectsRequest());

return response.Projects
.Where(x => context.SearchString == null || x.Name.Contains(context.SearchString, StringComparison.OrdinalIgnoreCase))
Expand Down
9 changes: 9 additions & 0 deletions Apps.XTM/Models/Request/Projects/ListProjectsRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Blackbird.Applications.Sdk.Common;

namespace Apps.XTM.Models.Request.Projects;

public class ListProjectsRequest
{
[Display("Project name")]
public string? Name { get; set; }
}
9 changes: 9 additions & 0 deletions Apps.XTM/Utils/DictionaryHelpers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Apps.XTM.Utils;

public static class DictionaryHelpers
{
public static string ToQueryString<T1, T2>(this Dictionary<T1, T2> dictionary)
{
return string.Join("&", dictionary.Select(kvp => $"{kvp.Key}={kvp.Value}"));
}
}

0 comments on commit d732fc4

Please sign in to comment.