Skip to content

Commit

Permalink
it now checks to see whether the user is non levy or they are a levy …
Browse files Browse the repository at this point in the history
…that is currently receving transfer funds for TM-133
  • Loading branch information
sscaife committed Sep 2, 2021
1 parent 4b8ab1a commit bff0df2
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using SFA.DAS.Authorization.EmployerUserRoles.Options;
using SFA.DAS.Authorization.Services;
using SFA.DAS.EAS.Account.Api.Client;
using SFA.DAS.EmployerFinance.Services;
using SFA.DAS.EmployerFinance.Web.ViewModels;
using SFA.DAS.HashingService;
Expand All @@ -12,6 +14,8 @@ public class TransfersOrchestrator
private readonly IAuthorizationService _authorizationService;
private readonly IHashingService _hashingService;
private readonly ILevyTransferMatchingService _levyTransferMatchingService;
private readonly IAccountApiClient _accountApiClient;
private readonly ICohortsService _cohortsService;

protected TransfersOrchestrator()
{
Expand All @@ -21,16 +25,40 @@ protected TransfersOrchestrator()
public TransfersOrchestrator(
IAuthorizationService authorizationService,
IHashingService hashingService,
ILevyTransferMatchingService levyTransferMatchingService)
ILevyTransferMatchingService levyTransferMatchingService,
IAccountApiClient accountApiClient,
ICohortsService cohortsService)
{
_authorizationService = authorizationService;
_hashingService = hashingService;
_levyTransferMatchingService = levyTransferMatchingService;
_accountApiClient = accountApiClient;
_cohortsService = cohortsService;
}

public async Task<OrchestratorResponse<TransfersIndexViewModel>> Index(string hashedAccountId)
{
bool renderCreateTransfersPledgeButton = await _authorizationService.IsAuthorizedAsync(EmployerUserRole.OwnerOrTransactor);
var accountDetail = await _accountApiClient.GetAccount(hashedAccountId).ConfigureAwait(false);
var cohortsCount = await _cohortsService.GetCohortsCount(accountDetail.AccountId).ConfigureAwait(false);

if (string.Compare(accountDetail.ApprenticeshipEmployerType, "Levy", StringComparison.OrdinalIgnoreCase) != 0 || cohortsCount > 0)
{
return new OrchestratorResponse<TransfersIndexViewModel>()
{
Data = new TransfersIndexViewModel()
{
CanViewTransfersSection = false
}
};
}

return await GenerateTransfersViewIndexModelForLevyAccounts(hashedAccountId);
}

private async Task<OrchestratorResponse<TransfersIndexViewModel>> GenerateTransfersViewIndexModelForLevyAccounts(string hashedAccountId)
{
bool renderCreateTransfersPledgeButton =
await _authorizationService.IsAuthorizedAsync(EmployerUserRole.OwnerOrTransactor);

var accountId = _hashingService.DecodeValue(hashedAccountId);

Expand All @@ -42,6 +70,7 @@ public async Task<OrchestratorResponse<TransfersIndexViewModel>> Index(string ha
{
RenderCreateTransfersPledgeButton = renderCreateTransfersPledgeButton,
PledgesCount = pledgesCount,
CanViewTransfersSection = true
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public class TransfersIndexViewModel
{
public bool CanViewTransfersSection { get; set; }
public bool RenderCreateTransfersPledgeButton { get; set; }
public int PledgesCount { get; set; }
}
Expand Down
33 changes: 18 additions & 15 deletions src/SFA.DAS.EmployerFinance.Web/Views/Transfers/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
ViewBag.ZenDeskLabel = "eas-finance";
}

<h1 class="heading-xlarge">Transfers</h1>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-m">My pledges</h2>
<p>Create a public funding pledge which is shown online so that businesses can apply to you for a transfer of funds.</p>
<div class="panel panel-border-wide">
You have <strong>@Model.Data.PledgesCount</strong> transfer pledges.
</div>
<div class="">
@if (Model.Data.RenderCreateTransfersPledgeButton)
{
<a class="button" href="@Url.LevyMatchingTransfersAction("pledges/create/inform")" id="CreateTransfersPledgeButton">Create a transfers pledge</a>
}
<a href="@Url.LevyMatchingTransfersAction("pledges")" class="button button-secondary">View my transfer pledges and applications</a>
@if (Model.Data.CanViewTransfersSection)
{
<h1 class="heading-xlarge">Transfers</h1>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-m">My pledges</h2>
<p>Create a public funding pledge which is shown online so that businesses can apply to you for a transfer of funds.</p>
<div class="panel panel-border-wide">
You have <strong>@Model.Data.PledgesCount</strong> transfer pledges.
</div>
<div class="">
@if (Model.Data.RenderCreateTransfersPledgeButton)
{
<a class="button" href="@Url.LevyMatchingTransfersAction("pledges/create/inform")" id="CreateTransfersPledgeButton">Create a transfers pledge</a>
}
<a href="@Url.LevyMatchingTransfersAction("pledges")" class="button button-secondary">View my transfer pledges and applications</a>
</div>
</div>
</div>
</div>
}

@section breadcrumb {
<div class="breadcrumbs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using SFA.DAS.EmployerFinance.Configuration;
using SFA.DAS.EmployerFinance.Infrastructure;
using SFA.DAS.EmployerFinance.Interfaces.OuterApi;
using SFA.DAS.EmployerFinance.Services;
using StructureMap;

namespace SFA.DAS.EmployerFinance.DependencyResolution
Expand All @@ -12,6 +13,7 @@ public ManageApprenticeshipsOuterApiRegistry ()
{
For<ManageApprenticeshipsOuterApiConfiguration>().Use(c => c.GetInstance<EmployerFinanceConfiguration>().ManageApprenticeshipsOuterApiConfiguration).Singleton();
For<IApiClient>().Use<ApiClient>().Ctor<HttpClient>().Is(new HttpClient()).Singleton();
For<ICohortsService>().Use<CohortsService>().Ctor<HttpClient>().Is(new HttpClient()).Ctor<string>().Is(c => c.GetInstance<EmployerFinanceConfiguration>().EmployerCommitmentsBaseUrl).Singleton();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFA.DAS.EmployerFinance.Interfaces.OuterApi;

namespace SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests
{
public class GetCohortsRequest : IGetApiRequest
{
private readonly long _accountId;

public GetCohortsRequest(long accountId)
{
_accountId = accountId;
}

public string GetUrl => $"api/cohorts?accountId={_accountId}";
}
}
14 changes: 14 additions & 0 deletions src/SFA.DAS.EmployerFinance/Models/Cohort/CurrentCohorts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SFA.DAS.CommitmentsV2.Types;

namespace SFA.DAS.EmployerFinance.Models.Cohort
{
public class CurrentCohorts
{
public List<CohortSummary> Cohorts { get; set; }
}
}
1 change: 1 addition & 0 deletions src/SFA.DAS.EmployerFinance/SFA.DAS.EmployerFinance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PackageReference Include="SFA.DAS.Caches" Version="1.1.4" />
<PackageReference Include="SFA.DAS.Commitments.Api.Client" Version="4.1.355" />
<PackageReference Include="SFA.DAS.Commitments.Api.Types" Version="4.1.355" />
<PackageReference Include="SFA.DAS.CommitmentsV2.Types" Version="7.71.0" />
<PackageReference Include="SFA.DAS.Common.Domain" Version="1.4.283" />
<PackageReference Include="SFA.DAS.Configuration" Version="1.0.0.53229" />
<PackageReference Include="SFA.DAS.Configuration.AzureTableStorage" Version="1.0.0.53229" />
Expand Down
38 changes: 38 additions & 0 deletions src/SFA.DAS.EmployerFinance/Services/CohortsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using SFA.DAS.CommitmentsV2.Types;
using SFA.DAS.EmployerFinance.Configuration;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests;
using SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses;
using SFA.DAS.EmployerFinance.Interfaces.OuterApi;
using SFA.DAS.EmployerFinance.Models.Cohort;

namespace SFA.DAS.EmployerFinance.Services
{
public class CohortsService : ICohortsService
{
private readonly HttpClient _httpClient;

public CohortsService(HttpClient httpClient, string cohortsBaseUrl)
{
_httpClient = httpClient;
_httpClient.BaseAddress = new Uri(cohortsBaseUrl);
}

public async Task<int> GetCohortsCount(long accountId)
{
var cohortsCountResponse = await _httpClient.GetAsync(new GetCohortsRequest(accountId).GetUrl).ConfigureAwait(false);

cohortsCountResponse.EnsureSuccessStatusCode();
var json = await cohortsCountResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
var currentCohorts = JsonConvert.DeserializeObject<CurrentCohorts>(json);

return currentCohorts.Cohorts.Count;
}
}
}
9 changes: 9 additions & 0 deletions src/SFA.DAS.EmployerFinance/Services/ICohortsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace SFA.DAS.EmployerFinance.Services
{
public interface ICohortsService
{
Task<int> GetCohortsCount(long accountId);
}
}

0 comments on commit bff0df2

Please sign in to comment.