Skip to content

Commit da60c21

Browse files
committedSep 19, 2023
Change ListWorkflows call to use StrawberryShake and IndicoV2
1 parent 74cba69 commit da60c21

File tree

7 files changed

+78
-8
lines changed

7 files changed

+78
-8
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ IndicoV2.StrawberryShake/Generated/
4747
user.runsettings
4848
/IndicoV2/Properties/PublishProfiles
4949
/Indico/Properties/PublishProfiles
50+
/.graphqlrc.json

‎IndicoV2.Abstractions/Workflows/Models/IWorkflow.cs

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ public interface IWorkflow
88
int Id { get; }
99

1010
bool ReviewEnabled { get; }
11+
12+
string Name { get; }
1113
}
1214
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using IndicoV2.StrawberryShake;
5+
6+
namespace IndicoV2.Workflows.Models
7+
{
8+
public class WorkflowSs : IWorkflow
9+
{
10+
private readonly IListWorkflows_Workflows_Workflows _ssWorkflow;
11+
public WorkflowSs(IListWorkflows_Workflows_Workflows workflow) => _ssWorkflow = workflow;
12+
public int Id => _ssWorkflow.Id ?? 0;
13+
public bool ReviewEnabled => _ssWorkflow.ReviewEnabled ?? false;
14+
public string Name => _ssWorkflow.Name;
15+
}
16+
}

‎IndicoV2.IntegrationTests/Workflows/WorkflowClientTests.cs

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using IndicoV2.IntegrationTests.Utils.Configs;
77
using IndicoV2.IntegrationTests.Utils.DataHelpers;
88
using IndicoV2.Workflows;
9+
using IndicoV2.Workflows.Models;
910
using NUnit.Framework;
1011
using Unity;
1112

@@ -61,5 +62,17 @@ public async Task AddData_ShouldReturnResult()
6162

6263
result.Should().NotBeNull();
6364
}
65+
66+
[Test]
67+
public async Task ListWorkflows_ShouldReturnResult()
68+
{
69+
var result = await _workflowsClient.ListAsync(_dataSetId);
70+
result.Should().NotBeNull();
71+
foreach (WorkflowSs wf in result)
72+
{
73+
wf.Id.Should().BeGreaterThan(0);
74+
wf.Name.Should().NotBeNull();
75+
}
76+
}
6477
}
6578
}

‎IndicoV2.StrawberryShake/Workflows/WorkflowSsClient.cs

+21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
using System.Linq;
22
using System.Threading;
33
using System.Threading.Tasks;
4+
using System.Collections.Generic;
45
using IndicoV2.StrawberryShake.Exceptions;
56
using Microsoft.Extensions.DependencyInjection;
7+
using System;
8+
using System.Data;
9+
using Newtonsoft.Json.Linq;
610

711
namespace IndicoV2.StrawberryShake.Workflows
812
{
@@ -23,5 +27,22 @@ public async Task<WorkflowStatus> GetStatus(int workflowId, CancellationToken ca
2327

2428
return response.Workflows.Workflows.Single().Status.Value;
2529
}
30+
31+
public async Task<IListWorkflows_Workflows> ListAsync(int datasetId, CancellationToken cancellationToken)
32+
{
33+
int?[] datasetIds = { datasetId };
34+
var response = await ExecuteAsync(() =>
35+
_services.GetRequiredService<ListWorkflowsQuery>().ExecuteAsync(Array.AsReadOnly(datasetIds), cancellationToken));
36+
return response.Workflows;
37+
}
38+
39+
public async Task<IListWorkflows_Workflows> ListAsync(int[] datasetIds, CancellationToken cancellationToken)
40+
{
41+
var nullableDatasetIds = datasetIds.Cast<int?>().ToArray();
42+
var response = await ExecuteAsync(() =>
43+
_services.GetRequiredService<ListWorkflowsQuery>().ExecuteAsync(Array.AsReadOnly(nullableDatasetIds), cancellationToken));
44+
return response.Workflows;
45+
}
46+
2647
}
2748
}

‎IndicoV2.StrawberryShake/Workflows/Workflows.graphql

+10
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ mutation WorkflowAddData($workflowId: Int!) {
1515
}
1616
}
1717
}
18+
19+
query ListWorkflows($datasetIds: [Int]){
20+
workflows(datasetIds: $datasetIds){
21+
workflows {
22+
id
23+
name
24+
reviewEnabled
25+
}
26+
}
27+
}

‎IndicoV2/Workflows/WorkflowsClient.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
11
using System.Collections.Generic;
22
using System.Threading;
33
using System.Threading.Tasks;
4+
using System.Linq;
45
using IndicoV2.StrawberryShake;
5-
using IndicoV2.V1Adapters.Workflows;
66
using IndicoV2.Workflows.Models;
77

88
namespace IndicoV2.Workflows
99
{
1010
public class WorkflowsClient : IWorkflowsClient
1111
{
12-
private readonly WorkflowsV1ClientAdapter _legacy;
1312
private readonly IndicoStrawberryShakeClient _strawberryShake;
13+
private readonly IndicoClient _indicoClient;
1414

1515
public WorkflowsClient(IndicoClient indicoClient)
1616
{
17-
_legacy = new WorkflowsV1ClientAdapter(indicoClient.LegacyClient);
17+
_indicoClient = indicoClient;
1818
_strawberryShake = indicoClient.IndicoStrawberryShakeClient;
1919
}
2020

21-
public Task<IEnumerable<IWorkflow>> ListAsync(int dataSetId, CancellationToken cancellationToken = default) =>
22-
_legacy.ListAsync(dataSetId, cancellationToken);
21+
public async Task<IEnumerable<IWorkflow>> ListAsync(int dataSetId, CancellationToken cancellationToken = default)
22+
{
23+
var result = await _strawberryShake.Workflows().ListAsync(dataSetId, cancellationToken);
24+
return result.Workflows.Select(x => ToWorkflowFromSs(x)).ToList();
25+
}
2326

24-
public Task<IEnumerable<IWorkflow>>
25-
ListAsync(int[] dataSetIds, CancellationToken cancellationToken = default) =>
26-
_legacy.ListAsync(dataSetIds, cancellationToken);
27+
public async Task<IEnumerable<IWorkflow>>ListAsync(int[] dataSetIds, CancellationToken cancellationToken = default)
28+
{
29+
var result = await _strawberryShake.Workflows().ListAsync(dataSetIds, cancellationToken);
30+
return result.Workflows.Select(x => ToWorkflowFromSs(x)).ToList();
31+
}
2732

2833
public Task<IWorkflowAddDataResult> AddDataAsync(int workflowId, CancellationToken cancellationToken) =>
2934
_strawberryShake.Workflows().AddData(workflowId, cancellationToken);
3035

3136
public Task<WorkflowStatus> GetStatusAsync(int workflowId, CancellationToken cancellationToken) =>
3237
_strawberryShake.Workflows().GetStatus(workflowId, cancellationToken);
38+
39+
private IWorkflow ToWorkflowFromSs(IListWorkflows_Workflows_Workflows workflow) => new WorkflowSs(workflow);
3340
}
3441
}

0 commit comments

Comments
 (0)
Please sign in to comment.