Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(summary): Add Task Owner Report endpoints #711

Merged
merged 18 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Fusion.Resources.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TBN/@EntryIndexedValue">TBN</s:String></wpf:ResourceDictionary>
3 changes: 3 additions & 0 deletions src/Fusion.Summary.Api/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public class BaseController : ControllerBase
protected ActionResult DepartmentNotFound(string sapDepartmentId) =>
FusionApiError.NotFound(sapDepartmentId, $"Department with sap id '{sapDepartmentId}' was not found");

protected ActionResult ProjectNotFound(Guid projectId) =>
FusionApiError.NotFound(projectId, $"Project with id or externalId '{projectId}' was not found");

protected ActionResult SapDepartmentIdRequired() =>
FusionApiError.InvalidOperation("SapDepartmentIdRequired", "SapDepartmentId route parameter is required");

Expand Down
28 changes: 28 additions & 0 deletions src/Fusion.Summary.Api/Controllers/ApiModels/ApiProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Fusion.Summary.Api.Domain.Models;

namespace Fusion.Summary.Api.Controllers.ApiModels;

public class ApiProject
{
public required Guid Id { get; set; }

public required string Name { get; set; }
public required Guid OrgProjectExternalId { get; set; }

public Guid? DirectorAzureUniqueId { get; set; }

public Guid[] AssignedAdminsAzureUniqueId { get; set; } = [];


public static ApiProject FromQueryProject(QueryProject queryProject)
{
return new ApiProject()
{
Id = queryProject.Id,
Name = queryProject.Name,
OrgProjectExternalId = queryProject.OrgProjectExternalId,
AssignedAdminsAzureUniqueId = queryProject.AssignedAdminsAzureUniqueId.ToArray(),
DirectorAzureUniqueId = queryProject.DirectorAzureUniqueId
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Fusion.Summary.Api.Domain.Models;

namespace Fusion.Summary.Api.Controllers.ApiModels;

public class ApiWeeklyTaskOwnerReport
{
public required Guid Id { get; set; }
public required Guid ProjectId { get; set; }
public required DateTime PeriodStart { get; set; }
public required DateTime PeriodEnd { get; set; }

public required int ActionsAwaitingTaskOwnerAction { get; set; }
public required ApiAdminAccessExpiring[] AdminAccessExpiringInLessThanThreeMonths { get; set; }
public required ApiPositionAllocationEnding[] PositionAllocationsEndingInNextThreeMonths { get; set; }
public required ApiTBNPositionStartingSoon[] TBNPositionsStartingInLessThanThreeMonths { get; set; }


public static ApiWeeklyTaskOwnerReport FromQueryWeeklyTaskOwnerReport(QueryWeeklyTaskOwnerReport queryReport)
{
return new ApiWeeklyTaskOwnerReport
{
Id = queryReport.Id,
ProjectId = queryReport.ProjectId,
PeriodStart = queryReport.Period.Start,
PeriodEnd = queryReport.Period.End,
ActionsAwaitingTaskOwnerAction = queryReport.ActionsAwaitingTaskOwnerAction,
AdminAccessExpiringInLessThanThreeMonths = queryReport.AdminAccessExpiringInLessThanThreeMonths.Select(x =>
new ApiAdminAccessExpiring()
{
AzureUniqueId = x.AzureUniqueId,
FullName = x.FullName,
Expires = x.Expires
}).ToArray(),
PositionAllocationsEndingInNextThreeMonths = queryReport.PositionAllocationsEndingInNextThreeMonths.Select(x =>
new ApiPositionAllocationEnding()
{
PositionName = x.PositionName,
PositionNameDetailed = x.PositionNameDetailed,
PositionAppliesTo = x.PositionAppliesTo,
PositionExternalId = x.PositionExternalId
}).ToArray(),
TBNPositionsStartingInLessThanThreeMonths = queryReport.TBNPositionsStartingInLessThanThreeMonths.Select(x =>
new ApiTBNPositionStartingSoon()
{
PositionName = x.PositionName,
PositionNameDetailed = x.PositionNameDetailed,
PositionAppliesFrom = x.PositionAppliesFrom,
PositionExternalId = x.PositionExternalId
}).ToArray()
};
}
}

public class ApiAdminAccessExpiring
{
public required Guid AzureUniqueId { get; set; }
public required string FullName { get; set; }
public required DateTime Expires { get; set; }
}

public class ApiPositionAllocationEnding
{
public required string PositionExternalId { get; set; }

public required string PositionName { get; set; }

public required string PositionNameDetailed { get; set; }

public required DateTime PositionAppliesTo { get; set; }
}

public class ApiTBNPositionStartingSoon
{
public required string PositionExternalId { get; set; }
public required string PositionName { get; set; }
public required string PositionNameDetailed { get; set; }
public required DateTime PositionAppliesFrom { get; set; }
}
12 changes: 0 additions & 12 deletions src/Fusion.Summary.Api/Controllers/DepartmentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,6 @@ public async Task<IActionResult> PutV1(string sapDepartmentId, [FromBody] PutDep
if (string.IsNullOrWhiteSpace(sapDepartmentId))
return SapDepartmentIdRequired();

var personIdentifiers = request.ResourceOwnersAzureUniqueId
.Concat(request.DelegateResourceOwnersAzureUniqueId)
.Select(p => new PersonIdentifier(p));

var unresolvedProfiles = (await ResolvePersonsAsync(personIdentifiers))
.Where(r => !r.Success)
.ToList();

if (unresolvedProfiles.Count != 0)
return FusionApiError.NotFound(string.Join(',', unresolvedProfiles), "Profiles could not be resolved");


var department = await DispatchAsync(new GetDepartment(sapDepartmentId));

// Check if department exist
Expand Down
110 changes: 110 additions & 0 deletions src/Fusion.Summary.Api/Controllers/ProjectsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
using System.Net.Mime;
using Fusion.AspNetCore.FluentAuthorization;
using Fusion.Authorization;
using Fusion.Integration.Profile;
using Fusion.Summary.Api.Authorization.Extensions;
using Fusion.Summary.Api.Controllers.ApiModels;
using Fusion.Summary.Api.Controllers.Requests;
using Fusion.Summary.Api.Domain.Commands;
using Fusion.Summary.Api.Domain.Queries;
using Microsoft.ApplicationInsights.AspNetCore.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Fusion.Summary.Api.Controllers;

[Authorize]
[ApiController]
[Produces(MediaTypeNames.Application.Json)]
[ApiVersion("1.0")]
public class ProjectsController : BaseController
{
[HttpGet("projects")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult<ApiProject[]>> GetProjectsV1()
{
#region Authorization

var authResult = await Request.RequireAuthorizationAsync(r =>
{
r.AlwaysAccessWhen().ResourcesFullControl();
r.AnyOf(or => { or.BeTrustedApplication(); });
});

if (authResult.Unauthorized)
return authResult.CreateForbiddenResponse();

#endregion Authorization

var projects = await DispatchAsync(new GetProjects());

var apiProjects = projects.Select(ApiProject.FromQueryProject);

return Ok(apiProjects);
}


[HttpGet("projects/{projectId:guid}")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<ApiProject?>> GetProjectsV1(Guid projectId)
{
#region Authorization

var authResult = await Request.RequireAuthorizationAsync(r =>
{
r.AlwaysAccessWhen().ResourcesFullControl();
r.AnyOf(or => { or.BeTrustedApplication(); });
});

if (authResult.Unauthorized)
return authResult.CreateForbiddenResponse();

#endregion Authorization

var projects = await DispatchAsync(new GetProjects().WhereProjectId(projectId));

var apiProjects = projects.Select(ApiProject.FromQueryProject);

return Ok(apiProjects.FirstOrDefault());
}

[HttpPut("projects/{projectId:guid}")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ApiProject?>> PutProjectsV1(Guid projectId, PutProjectRequest request)
{
#region Authorization

var authResult = await Request.RequireAuthorizationAsync(r =>
{
r.AlwaysAccessWhen().ResourcesFullControl();
r.AnyOf(or => { or.BeTrustedApplication(); });
});

if (authResult.Unauthorized)
return authResult.CreateForbiddenResponse();

#endregion Authorization

if (projectId == Guid.Empty)
return FusionApiError.InvalidOperation("ProjectIdRequired", "ProjectId route parameter is required and cannot be empty");

var project = (await DispatchAsync(new GetProjects().WhereProjectId(projectId))).FirstOrDefault();

if (project == null)
{
project = await DispatchAsync(new CreateProject(request).WithProjectId(projectId));

return Created(Request.GetUri(), ApiProject.FromQueryProject(project));
}

project = await DispatchAsync(new UpdateProject(project.Id, request));

return Ok(ApiProject.FromQueryProject(project));
}
}
23 changes: 23 additions & 0 deletions src/Fusion.Summary.Api/Controllers/Requests/PutProjectRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FluentValidation;

namespace Fusion.Summary.Api.Controllers.Requests;

public class PutProjectRequest
{
public required string Name { get; set; }
public required Guid OrgProjectExternalId { get; set; }

public Guid? DirectorAzureUniqueId { get; set; }

public Guid[] AssignedAdminsAzureUniqueId { get; set; } = [];


public class Validator : AbstractValidator<PutProjectRequest>
{
public Validator()
{
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.OrgProjectExternalId).NotEmpty();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using FluentValidation;
using Fusion.Summary.Api.Controllers.ApiModels;

namespace Fusion.Summary.Api.Controllers.Requests;

public class PutWeeklyTaskOwnerReportRequest
{
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }

public required int ActionsAwaitingTaskOwnerAction { get; set; }
public required ApiAdminAccessExpiring[] AdminAccessExpiringInLessThanThreeMonths { get; set; }
public required ApiPositionAllocationEnding[] PositionAllocationsEndingInNextThreeMonths { get; set; }
public required ApiTBNPositionStartingSoon[] TBNPositionsStartingInLessThanThreeMonths { get; set; }


public class Validator : AbstractValidator<PutWeeklyTaskOwnerReportRequest>
{
public Validator()
{
RuleFor(x => x.PeriodStart).NotEmpty();
RuleFor(x => x.PeriodEnd).NotEmpty();
RuleFor(x => x.PeriodStart).LessThan(x => x.PeriodEnd);
RuleFor(x => x.PeriodStart).Must(x => x.DayOfWeek == DayOfWeek.Monday).WithMessage("Period start must be a Monday");
RuleFor(x => x.PeriodEnd).Must(x => x.DayOfWeek == DayOfWeek.Monday).WithMessage("Period end must be a Monday");

RuleFor(x => x)
.Must(x => x.PeriodEnd.Date == x.PeriodStart.Date.AddDays(7))
.WithMessage("Period must be exactly 7 days");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Fusion.Summary.Api.Controllers;
[Authorize]
[ApiController]
[ApiVersion("1.0")]
public class SummaryReportsController : BaseController
public class ResourceOwnerReportsController : BaseController
{
[HttpGet("resource-owners-summary-reports/{sapDepartmentId}/weekly")]
[MapToApiVersion("1.0")]
Expand Down
Loading
Loading