This commit is contained in:
2026-11-21 17:47:56 +03:30
parent bc66d86ed2
commit 102e95c59d
10 changed files with 995 additions and 25 deletions
+193 -16
View File
@@ -122,7 +122,60 @@ namespace xApi.Providers
return result;
}
public async Task<string> GetWorkItemTypesAsync(
/// <summary>
/// Retrieve Specified Work Item ...
/// </summary>
/// <param name="workItemId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<AzureWorkItemDto> GetWorkItemAsync(
long workItemId,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (workItemId <= 0)
{
//
var message = "Invalid Args ...";
//
logger.LogError(message);
throw new ArgumentException(message);
}
//
// Prepare WorkItem Path ...
var path = $"{AzureEndpoints.WorkItemsBaseEndpoint}/{workItemId}";
var json = await HandleAzureRequest(
path: path,
method: HttpMethod.Get,
cancellationToken: cancellationToken
);
//
var result = json.ParseJSON<AzureWorkItemDto>();
if (result is null)
{
//
var message = "Failed to parse Azure data ...";
//
logger.LogError(message);
throw new InvalidOperationException(message);
}
//
return result;
}
/// <summary>
/// Retrieve Work Item Fields ...
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<AzureListDto<AzureWorkItemFieldDto>> GetWorkItemFieldsAsync(
CancellationToken cancellationToken = default
)
{
@@ -130,26 +183,111 @@ namespace xApi.Providers
var json = await HandleAzureRequest(
method: HttpMethod.Get,
cancellationToken: cancellationToken,
path: AzureEndpoints.WorkItemsODataEndpoint
path: AzureEndpoints.WorkItemFieldsEndpoint
);
//
return json;
var result = json.ParseJSON<AzureListDto<AzureWorkItemFieldDto>>();
if (result is null)
{
//
var message = "Failed to parse Azure data ...";
//
logger.LogError(message);
throw new InvalidOperationException(message);
}
//
// var result = json.ParseJSON<AzureListDto<AzureRepositoryDto>>();
// if (result is null)
// {
// //
// var message = "Failed to parse Azure data ...";
return result;
}
// //
// logger.LogError(message);
// throw new InvalidOperationException(message);
// }
/// <summary>
/// Get Specified Project's WorkItem Types ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<AzureListDto<AzureWorkItemTypeDto>> GetProjectWorkItemTypesAsync(
Guid id,
CancellationToken cancellationToken = default
)
{
//
// Prepare Custom Path for WorkItem ...
var path = $"{PrepareProjectBaseUrl(id)}/{AzureEndpoints.WorkItemTypesEndpoint.NormalizeUrlSegent()}";
// //
// return result;
//
var json = await HandleAzureRequest(
path: path,
forceApiSuffix: false,
method: HttpMethod.Get,
forceJsonValidation: true,
cancellationToken: cancellationToken
);
//
var result = json.ParseJSON<AzureListDto<AzureWorkItemTypeDto>>();
if (result is null)
{
//
var message = "Failed to parse Azure data ...";
//
logger.LogError(message);
throw new InvalidOperationException(message);
}
//
return result;
}
/// <summary>
/// Get Specified WorkItem Revisions (History) ...
/// </summary>
/// <param name="workItemId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<AzureListDto<WorkItemRevisionDto>> GetWorkItemRevisionsAsync(
long workItemId,
CancellationToken cancellationToken = default
)
{
//
// Validate ...
if (workItemId <= 0)
{
//
var message = "Invalid Args ...";
//
logger.LogError(message);
throw new ArgumentException(message);
}
//
// Prepare WorkItem Path ...
var path = $"{AzureEndpoints.WorkItemsBaseEndpoint}/{workItemId}/revisions";
var json = await HandleAzureRequest(
path: path,
method: HttpMethod.Get,
cancellationToken: cancellationToken
);
//
var result = json.ParseJSON<AzureListDto<WorkItemRevisionDto>>();
if (result is null)
{
//
var message = "Failed to parse Azure data ...";
//
logger.LogError(message);
throw new InvalidOperationException(message);
}
//
return result;
}
//
@@ -159,6 +297,7 @@ namespace xApi.Providers
/// </summary>
/// <param name="path"></param>
/// <param name="method"></param>
/// <param name="forceApiSuffix"></param>
/// <param name="forceJsonValidation"></param>
/// <param name="headers"></param>
/// <param name="queryParams"></param>
@@ -168,6 +307,7 @@ namespace xApi.Providers
private async Task<string> HandleAzureRequest(
string path,
HttpMethod method,
bool forceApiSuffix = true,
bool forceJsonValidation = true,
IDictionary<string, string>? headers = null,
IDictionary<string, string>? queryParams = null,
@@ -217,6 +357,26 @@ namespace xApi.Providers
{
url += "/";
}
//
// Handle Suffix ...
if (forceApiSuffix &&
!string.IsNullOrWhiteSpace(configuration.ApiSuffix)
)
{
//
var suffix = configuration.ApiSuffix;
if (suffix.StartsWith('/'))
{
suffix = suffix[1..];
}
//
url += $"{suffix}/";
}
//
// Normalize Path ...
if (path.StartsWith('/'))
{
path = path[1..];
@@ -225,7 +385,8 @@ namespace xApi.Providers
//
// Handle Route Params ...
if (routeParams is not null &&
routeParams.Any())
routeParams.Any()
)
{
//
var exists =
@@ -255,7 +416,8 @@ namespace xApi.Providers
//
// Applying Headers ...
if (headers is not null &&
headers.Any())
headers.Any()
)
{
//
foreach (var header in headers)
@@ -275,6 +437,7 @@ namespace xApi.Providers
}
//
// Handle Request ...
try
{
//
@@ -340,6 +503,20 @@ namespace xApi.Providers
//
return result;
}
private string PrepareProjectBaseUrl(
Guid id
)
{
//
var result = $"{id}/{configuration.ApiSuffix?.NormalizeUrlSegent()}";
if (result.EndsWith('/')) {
result = result[..^1];
}
//
return result;
}
#endregion
}
}