Skip to content

JT - Migrate WorkforceManagementApi.cs #113

@JackTelford

Description

@JackTelford

PureCloud.Client API Migration Guide

Modernize legacy async client methods into /src/PureCloud.Client/Apis/, preserving functionality and aligning with current conventions.


Source & Destination

  • From: /src/PureCloud.Client/OldApis/
  • To: /src/PureCloud.Client/Apis/
  • Maintain one‑to‑one file mapping.

Core Guidelines

  1. Async‑Only

    • Migrate only methods already marked async.
    • Retain async and add a CancellationToken parameter.
  2. Single Representative Method

    • Migrate one method per API; omit overloads or variations.
  3. Method Naming

    • Prefix methods with: Get…, Create…, Update…, or Delete….
  4. Reference Pattern

    • Structure & DI match /src/PureCloud.Client/Apis/FlowsApi.cs.
    • Target
      • Source: /src/PureCloud.Client/OldApis/WorkforceManagementApi.cs
      • Target: /src/PureCloud.Client/Apis/WorkforceManagementApi.cs

Code Example: FlowsApi

/// <inheritdoc />
public sealed class FlowsApi : IFlowsApi
{
    private readonly HttpClient _httpClient;
    private readonly JsonSerializerOptions _options;

    public FlowsApi(IHttpClientFactory httpClientFactory, IOptions<PureCloudJsonSerializerOptions> options)
    {
        _httpClient = httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);
        _options    = options.Value.JsonSerializerOptions;
    }

    /// <inheritdoc />
    public async Task<FlowResponse[]> GetFlowsAsync(string conversationId, CancellationToken cancellationToken)
    {
        ArgumentException.ThrowIfNullOrEmpty(nameof(conversationId), conversationId);

        var parameters = new NameValueCollection { { "conversationId", conversationId } };
      
        var uri        = UriHelper.GetUri("/api/v2/flows", parameters);

        var response = await _httpClient.GetAsync(uri, cancellationToken);
       
        response.EnsureSuccessStatusCode();

        return await response.Content.ReadFromJsonAsync<FlowResponse[]>(_options, cancellationToken);
    }
}

Infrastructure & URI Handling

  • HttpClient:

    var client = _httpClientFactory.CreateClient(PureCloudConstants.PureCloudClientName);
  • URI builder:

    var uri = UriHelper.GetUri("api/v2/webchat/settings", null);
  • Query params: use NameValueCollection; omit (pass null) when none are required.


HTTP & JSON Helpers

  • GET: await client.GetAsync(uri, cancellationToken)

  • DELETE: await client.DeleteAsync(uri, cancellationToken)

  • POST: await client.PostAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)

  • PUT: await client.PutAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)

  • PATCH: await client.PatchAsJsonAsync(uri, body, _options.JsonSerializerOptions, cancellationToken)

  • Deserialize:

    return await response.Content.ReadFromJsonAsync<T>(_options, cancellationToken);

Code Style & Formatting

  • 1 Seal all classes.
  • 2 End each file with a single newline.
  • 3 Document methods with /// <inheritdoc /> and a blank line.
  • 4 Use IEnumerable<> instead of List<>.
  • 5 Return arrays, never List<>.
  • 6 Single‑line method signatures (no stacked parameters).
  • 7 Blank line before each return.
  • 8 Validate inputs with ArgumentException.ThrowIfNullOrEmpty(...) (blank line after).
  • 9 Remove all unnecessary comments.

Model include into solution

  • 1 Convert all partial classes to sealed classes.
  • 2 Remove all IEquatable<> implementations.
  • 3 Extract enums into <Base>.<Descriptor>.cs (e.g., HelloWorld.Status.cs), dropping “Enum”.
  • 4 Remove [JsonPropertyName], constructors, and overrides (ToString(), Equals(), GetHashCode()).
  • 5 Replace List<> properties with IEnumerable<>.

Include Models

  • 1 Generate or migrate request/response models under src/PureCloud.Client/Models/.
  • 2 Never rename models—keep original class names.
  • 3 Apply Model Cleanup rules.
  • 4 Add each model to the .csproj.

Model Cleanup Verification

After you output all files, include a “✅ Model Cleanup Checklist” section exactly like this:

1 Converted all partial classes to sealed
2 Removed all IEquatable<> implementations
3 Extracted enums into <Base>.<Descriptor>.cs
4 Removed [JsonPropertyName], constructors, and overrides (ToString(), Equals(), GetHashCode())
5 Replaced all List<> properties with IEnumerable<>

6 Only then change the title to completed + Name.

7 Include the model add to PureCloud.Client\Extensions\ServiceCollectionExtensions.cs
8 Include the model add to src\PureCloud.Client\PureCloud.Client.csproj

URL Coverage Validation include a “✅ when completed

  • 1 Extract literal URLs from old code.
  • 2 Confirm each appears in new methods via UriHelper.GetUri.
  • 3 If missing or altered, insert a // TODO: Missing URL comment.
  • 4 Expected AsyncWithHttpInfo Methods Converted 86 Check ** Importent ** for file WorkforceManagementApi.cs

Completion Summary

After generation, provide a summary that:

  1. Lists all API and model files created or modified.
  2. Confirms adherence to Core Guidelines, Code Style, and Model Cleanup rules.
  3. Verifies URL coverage.
  4. Notes any special cases or manual interventions.

include a “✅ when completed Include the model add to PureCloud.Client\Extensions\ServiceCollectionExtensions.cs
include a “✅ when completed Include the model add to src\PureCloud.Client\PureCloud.Client.csproj

Do not include extra explanations—output only the final C# files ready to drop into
/src/PureCloud.Client/Apis/ and src/PureCloud.Client/Models/.

Once Finish Change the Title to completed + Name

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions