Skip to content

Commit

Permalink
Update notifications: AverageTimeToHandleRequests and ChangesForResou…
Browse files Browse the repository at this point in the history
…rceDepartment
  • Loading branch information
aleklundeq committed Dec 11, 2023
1 parent f33d72c commit 5034621
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Fusion.ApiClients.Org;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Fusion.Resources.Functions.ApiClients;

public interface IOrgClient
{
Task<ApiChangeLog> GetChangeLog(string projectId, string positionId, string instanceId);
}


#region model
public class ApiChangeLog
{
public Guid ProjectId { get; set; }
public DateTimeOffset? FirstEventDate { get; set; }
public DateTimeOffset? LastEventDate { get; set; }
public List<ApiChangeLogEvent> Events { get; set; }

}

public class ApiChangeLogEvent
{

public Guid? PositionId { get; set; }
public string? PositionName { get; set; }

Check warning on line 30 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public string? PositionExternalId { get; set; }

Check warning on line 31 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public Guid? InstanceId { get; set; }
public string Name { get; set; }
public string ChangeCategory { get; set; }
public ApiPersonV2? Actor { get; set; }

Check warning on line 35 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public DateTimeOffset TimeStamp { get; set; }
public string? Description { get; set; }

Check warning on line 37 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public string ChangeType { get; set; }
public object? PayLoad { get; set; }

Check warning on line 39 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

public ApiInstanceSnapshot? Instance { get; init; }

Check warning on line 41 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

public Guid EventId { get; set; }
public string EventFriendlyName { get; set; }

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public Guid? DraftId { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? ChangeSource { get; set; }

Check warning on line 49 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string? ChangeSourceId { get; set; }

Check warning on line 51 in src/backend/function/Fusion.Resources.Functions/ApiClients/IOrgApiClient.cs

View workflow job for this annotation

GitHub Actions / build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

public class ApiInstanceSnapshot
{
public DateTime? AppliesFrom { get; set; }
public DateTime? AppliesTo { get; set; }
public double? WorkLoad { get; set; }
}
}

public enum ChangeType
{
PositionInstanceCreated,
PersonAssignedToPosition,
PositionInstanceAllocationStateChanged,
PositionInstanceAppliesToChanged,
PositionInstanceAppliesFromChanged,
PositionInstanceParentPositionIdChanged,
PositionInstancePercentChanged,
PositionInstanceLocationChanged
}

#endregion
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ public class ResourceAllocationRequest
public ProposedPerson? ProposedPerson { get; set; }
public bool HasProposedPerson => ProposedPerson?.Person.AzureUniquePersonId is not null;
public string? State { get; set; }
public Workflow? workflow { get; set; }
public Workflow? Workflow { get; set; }
public DateTimeOffset Created { get; set; }
public InternalPersonnelPerson? CreatedBy { get; set; }

public DateTimeOffset? Updated { get; set; }
public InternalPersonnelPerson? UpdatedBy { get; set; }
public DateTimeOffset? LastActivity { get; set; }
Expand All @@ -49,12 +48,9 @@ public class Workflow
{
public string LogicAppName { get; set; }
public string LogicAppVersion { get; set; }

[JsonConverter(typeof(JsonStringEnumConverter))]
public ApiWorkflowState State { get; set; }

public IEnumerable<WorkflowStep> Steps { get; set; }

public enum ApiWorkflowState { Running, Canceled, Error, Completed, Terminated, Unknown }

}
Expand All @@ -63,25 +59,20 @@ public class WorkflowStep
{
public string Id { get; set; }
public string Name { get; set; }

public bool IsCompleted => Completed.HasValue;

/// <summary>
/// Pending, Approved, Rejected, Skipped
/// </summary>
[JsonConverter(typeof(JsonStringEnumConverter))]
public ApiWorkflowStepState State { get; set; }

public DateTimeOffset? Started { get; set; }
public DateTimeOffset? Completed { get; set; }
public DateTimeOffset? DueDate { get; set; }
public InternalPersonnelPerson? CompletedBy { get; set; }
public string Description { get; set; }
public string? Reason { get; set; }

public string? PreviousStep { get; set; }
public string? NextStep { get; set; }

public enum ApiWorkflowStepState { Pending, Approved, Rejected, Skipped, Unknown }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Fusion.Resources.Functions.ApiClients.ApiModels;
using Fusion.Resources.Functions.Integration;

namespace Fusion.Resources.Functions.ApiClients;

public class OrgClient : IOrgClient
{
private readonly HttpClient orgClient;

public OrgClient(IHttpClientFactory httpClientFactory)
{
orgClient = httpClientFactory.CreateClient(HttpClientNames.Application.Org);
orgClient.Timeout = TimeSpan.FromMinutes(5);
}

public async Task<ApiChangeLog> GetChangeLog(string projectId, string positionId, string instanceId)
{
var data =
await orgClient.GetAsJsonAsync<ApiChangeLog>($"/projects/{projectId}/positions/{positionId}/instances/{instanceId}/change-log?api-version=2.0");

return data;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public static IServiceCollection AddHttpClients(this IServiceCollection services
builder.AddNotificationsClient();
services.AddScoped<INotificationApiClient, NotificationApiClient>();

builder.AddOrgClient();
services.AddScoped<IOrgClient, OrgClient>();

return services;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ResourceOwnerAdaptiveCardData
public int NumberOfOpenRequests { get; set; }
public int NumberOfRequestsStartingInMoreThanThreeMonths { get; set; }
public int NumberOfRequestsStartingInLessThanThreeMonths { get; set; }
public int AverageTimeToHandleRequests { get; set; }
public double AverageTimeToHandleRequests { get; set; }
public int AllocationChangesAwaitingTaskOwnerAction { get; set; }
public int ProjectChangesAffectingNextThreeMonths { get; set; }
internal IEnumerable<PersonnelContent> PersonnelPositionsEndingWithNoFutureAllocation { get; set; }
Expand Down
Loading

0 comments on commit 5034621

Please sign in to comment.