Skip to content

Commit 3cb89b3

Browse files
committed
Add Approve and reject action as well as getting pending approvals list to the SDK and do some code cleaning
#44
1 parent cfbf9f0 commit 3cb89b3

File tree

6 files changed

+115
-3
lines changed

6 files changed

+115
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace FlowSynx.Client.Messages.Requests.Workflows;
2+
3+
public class ApproveWorkflowRequest
4+
{
5+
public required Guid WorkflowId { get; set; }
6+
public required Guid WorkflowExecutionId { get; set; }
7+
public required Guid WorkflowExecutionApprovalId { get; set; }
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace FlowSynx.Client.Messages.Requests.Workflows;
2+
3+
public class RejectWorkflowRequest
4+
{
5+
public required string WorkflowId { get; set; }
6+
public required string WorkflowExecutionId { get; set; }
7+
public required string WorkflowExecutionApprovalId { get; set; }
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace FlowSynx.Client.Messages.Requests.Workflows;
2+
3+
public class WorkflowExecutionPendingApprovalsRequest
4+
{
5+
public required Guid WorkflowId { get; set; }
6+
public required Guid WorkflowExecutionId { get; set; }
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace FlowSynx.Client.Messages.Responses.Workflows;
2+
3+
public class WorkflowExecutionPendingApprovalsResponse
4+
{
5+
public Guid Id { get; set; }
6+
public required Guid WorkflowId { get; set; }
7+
public required Guid ExecutionId { get; set; }
8+
public required string TaskName { get; set; } = default!;
9+
public string RequestedBy { get; set; } = default!;
10+
public DateTime RequestedAt { get; set; }
11+
public string? Status { get; set; }
12+
public string? Comments { get; set; }
13+
}

src/FlowSynx.Client/Services/IWorkflowsService.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,36 @@ Task<HttpResult<Result<Unit>>> CancelExecutionsAsync(
9797
CancelWorkflowRequest request,
9898
CancellationToken cancellationToken = default);
9999

100+
/// <summary>
101+
/// Retrieves a list of workflow execution approvals.
102+
/// </summary>
103+
/// <param name="request">The request for the approvals list.</param>
104+
/// <param name="cancellationToken">Token to cancel the asynchronous operation.</param>
105+
/// <returns>A result containing a collection of workflow execution approval responses.</returns>
106+
Task<HttpResult<Result<IEnumerable<WorkflowExecutionPendingApprovalsResponse>>>> ExecutionPendingApprovalsAsync(
107+
WorkflowExecutionPendingApprovalsRequest request,
108+
CancellationToken cancellationToken = default);
109+
110+
/// <summary>
111+
/// Approves a pending workflow execution.
112+
/// </summary>
113+
/// <param name="request">The request identifying which execution to approve.</param>
114+
/// <param name="cancellationToken">Token to cancel the asynchronous operation.</param>
115+
/// <returns>A result indicating success or failure of the approval.</returns>
116+
Task<HttpResult<Result<Unit>>> ApproveExecutionsAsync(
117+
ApproveWorkflowRequest request,
118+
CancellationToken cancellationToken = default);
119+
120+
/// <summary>
121+
/// Rejects a pending workflow execution.
122+
/// </summary>
123+
/// <param name="request">The request identifying which execution to reject.</param>
124+
/// <param name="cancellationToken">Token to cancel the asynchronous operation.</param>
125+
/// <returns>A result indicating success or failure of the rejection.</returns>
126+
Task<HttpResult<Result<Unit>>> RejectExecutionsAsync(
127+
RejectWorkflowRequest request,
128+
CancellationToken cancellationToken = default);
129+
100130
/// <summary>
101131
/// Retrieves logs for a specific workflow execution.
102132
/// </summary>

src/FlowSynx.Client/Services/WorkflowsService.cs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public async Task<HttpResult<Result<WorkflowExecutionDetailsResponse>>> Executio
120120
{
121121
HttpMethod = HttpMethod.Get,
122122
Uri = $"workflows/{request.WorkflowId.ToString()}/" +
123-
$"executions/{request.WorkflowExecutionId}"
123+
$"executions/{request.WorkflowExecutionId.ToString()}"
124124
};
125125

126126
return await _httpRequestHandler
@@ -135,13 +135,59 @@ public async Task<HttpResult<Result<Unit>>> CancelExecutionsAsync(
135135
{
136136
HttpMethod = HttpMethod.Post,
137137
Uri = $"workflows/{request.WorkflowId.ToString()}/" +
138-
$"executions/{request.WorkflowExecutionId}/cancel"
138+
$"executions/{request.WorkflowExecutionId.ToString()}/cancel"
139139
};
140140

141141
return await _httpRequestHandler
142142
.SendRequestAsync<Result<Unit>>(requestMessage, cancellationToken);
143143
}
144144

145+
public async Task<HttpResult<Result<IEnumerable<WorkflowExecutionPendingApprovalsResponse>>>> ExecutionPendingApprovalsAsync(
146+
WorkflowExecutionPendingApprovalsRequest request,
147+
CancellationToken cancellationToken = default)
148+
{
149+
var requestMessage = new Request
150+
{
151+
HttpMethod = HttpMethod.Get,
152+
Uri = $"workflows/{request.WorkflowId.ToString()}/" +
153+
$"executions/{request.WorkflowExecutionId.ToString()}/approvals"
154+
};
155+
156+
return await _httpRequestHandler
157+
.SendRequestAsync<Result<IEnumerable<WorkflowExecutionPendingApprovalsResponse>>>(requestMessage, cancellationToken);
158+
}
159+
160+
public async Task<HttpResult<Result<Unit>>> ApproveExecutionsAsync(
161+
ApproveWorkflowRequest request,
162+
CancellationToken cancellationToken = default)
163+
{
164+
var requestMessage = new Request
165+
{
166+
HttpMethod = HttpMethod.Post,
167+
Uri = $"workflows/{request.WorkflowId.ToString()}/" +
168+
$"executions/{request.WorkflowExecutionId.ToString()}/" +
169+
$"approvals/{request.WorkflowExecutionApprovalId.ToString()}/approve"
170+
};
171+
172+
return await _httpRequestHandler
173+
.SendRequestAsync<Result<Unit>>(requestMessage, cancellationToken);
174+
}
175+
176+
public async Task<HttpResult<Result<Unit>>> RejectExecutionsAsync(
177+
RejectWorkflowRequest request,
178+
CancellationToken cancellationToken = default)
179+
{
180+
var requestMessage = new Request
181+
{
182+
HttpMethod = HttpMethod.Post,
183+
Uri = $"workflows/{request.WorkflowId.ToString()}/" +
184+
$"executions/{request.WorkflowExecutionId.ToString()}/" +
185+
$"approvals/{request.WorkflowExecutionApprovalId.ToString()}/reject"
186+
};
187+
188+
return await _httpRequestHandler
189+
.SendRequestAsync<Result<Unit>>(requestMessage, cancellationToken);
190+
}
145191
public async Task<HttpResult<Result<WorkflowExecutionLogsResponse>>> ExecutionsLogsAsync(
146192
WorkflowExecutionLogsRequest request,
147193
CancellationToken cancellationToken = default)
@@ -150,7 +196,7 @@ public async Task<HttpResult<Result<WorkflowExecutionLogsResponse>>> ExecutionsL
150196
{
151197
HttpMethod = HttpMethod.Get,
152198
Uri = $"workflows/{request.WorkflowId.ToString()}/" +
153-
$"executions/{request.WorkflowExecutionId}/logs"
199+
$"executions/{request.WorkflowExecutionId.ToString()}/logs"
154200
};
155201

156202
return await _httpRequestHandler

0 commit comments

Comments
 (0)