Skip to content

Commit

Permalink
Merge branch 'master' into TM-142-Breadcrumb-Links
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisfoster76 committed Nov 12, 2021
2 parents 60a2716 + a1f8970 commit 2f25ac2
Show file tree
Hide file tree
Showing 50 changed files with 511 additions and 756 deletions.
2 changes: 1 addition & 1 deletion azure/finance.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,4 @@
"value": "[variables('workerAppServiceName')]"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<Build Include="Tables\TransactionLine_EOF.sql" />
<Build Include="StoredProcedures\CreateDraftExpiredFunds.sql" />
<Build Include="StoredProcedures\GetDraftExpiredFunds.sql" />
<Build Include="StoredProcedures\CreateAccountTransfersV1.sql" />
</ItemGroup>
<ItemGroup>
<None Include="Database.publish.xml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
CREATE PROCEDURE [employer_financial].[CreateAccountTransfersV1]
@transfers [employer_financial].[AccountTransferTable] READONLY
AS
INSERT INTO [employer_financial].[AccountTransfers]
(
SenderAccountId,
SenderAccountName,
ReceiverAccountId,
ReceiverAccountName,
ApprenticeshipId,
CourseName,
CourseLevel,
PeriodEnd,
Amount,
Type,
CreatedDate,
RequiredPaymentId
)
Select
tr.SenderAccountId,
actSender.Name,
tr.ReceiverAccountId,
actReceiver.Name,
tr.ApprenticeshipId,
IsNull(Ir.CourseName, 'Unknown Course'),
Ir.CourseLevel,
tr.PeriodEnd,
tr.Amount,
tr.Type, GetDate(),
tr.RequiredPaymentId
FROM
(SELECT
p.AccountId,
p.PeriodEnd,
p.ApprenticeshipId,
meta.ApprenticeshipCourseName as CourseName
,meta.ApprenticeshipCourseLevel as CourseLevel
,COUNT(DISTINCT Uln) as ApprenticeCount
,SUM(p.Amount) as PaymentTotal
FROM [employer_financial].[Payment] p
INNER JOIN [employer_financial].[PaymentMetaData] meta ON p.PaymentMetaDataId = meta.Id
Inner join @transfers tr on p.AccountId = tr.ReceiverAccountId and p.PeriodEnd = tr.PeriodEnd and p.ApprenticeshipId = tr.ApprenticeshipId
GROUP BY meta.ApprenticeshipCourseName, meta.ApprenticeshipCourseLevel, p.AccountId, p.PeriodEnd, p.ApprenticeshipId) Ir
Inner join @transfers tr on Ir.AccountId = tr.ReceiverAccountId and Ir.PeriodEnd = tr.PeriodEnd and Ir.ApprenticeshipId = tr.ApprenticeshipId
Inner join [employer_financial].[Account] actSender on actSender.Id = tr.SenderAccountId
Inner join [employer_financial].[Account] actReceiver on actReceiver.Id = tr.ReceiverAccountId
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ CREATE NONCLUSTERED INDEX [IX_Payment_AccountIdUkprnPeriodEndUln] ON [employer_f
GO

CREATE NONCLUSTERED INDEX [IX_Payment_AccountIdCollectionPeriodMonthCollectionPeriodYear] ON [employer_financial].[Payment] ([AccountId], [CollectionPeriodMonth], [CollectionPeriodYear]) INCLUDE ([Amount], [ApprenticeshipId], [CollectionPeriodId], [DeliveryPeriodMonth], [DeliveryPeriodYear], [FundingSource], [PaymentMetaDataId], [PeriodEnd], [Ukprn], [Uln]) WITH (ONLINE = ON)
GO

CREATE NONCLUSTERED INDEX [IX_Payment_Ukprn] ON [employer_financial].[Payment] ([Ukprn]) WITH (ONLINE = ON)
GO

CREATE NONCLUSTERED INDEX [IX_Payment_UkprnAccountId] ON [employer_financial].[Payment] ([AccountId], [Ukprn]) WITH (ONLINE = ON)
GO
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ GO

CREATE UNIQUE NONCLUSTERED INDEX [UK_TransactionLine_AccountId_TransactionType_TransactionDate] ON [employer_financial].[TransactionLine] ([AccountId] ASC, [TransactionType] ASC, [TransactionDate] ASC) WHERE [TransactionType] = /*ExpiredFund*/ 5
GO

CREATE INDEX [IX_TransactionLine_Account_DateCreated] ON [employer_financial].[TransactionLine] (AccountId, DateCreated) WITH (ONLINE = ON)
GO
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
CREATE TYPE [employer_financial].[AccountTransferTable] AS TABLE
(
SenderAccountId BIGINT NOT NULL,
SenderAccountName NVARCHAR(100) NOT NULL,
SenderAccountName NVARCHAR(100),
ReceiverAccountId BIGINT NOT NULL,
ReceiverAccountName NVARCHAR(100) NOT NULL,
ReceiverAccountName NVARCHAR(100),
ApprenticeshipId BIGINT NOT NULL,
CourseName VARCHAR(MAX) NOT NULL,
CourseName VARCHAR(MAX),
CourseLevel INT,
Amount DECIMAL(18,5) NOT NULL,
PeriodEnd NVARCHAR(20) NOT NULL,
Type NVARCHAR(50) NOT NULL,
RequiredPaymentId UNIQUEIDENTIFIER NOT NULL
RequiredPaymentId UNIQUEIDENTIFIER
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using SFA.DAS.EmployerAccounts.Api.Controllers;
using SFA.DAS.EmployerAccounts.Api.Types;
using SFA.DAS.EmployerAccounts.Queries.GetTransferConnections;
using SFA.DAS.HashingService;

namespace SFA.DAS.EmployerAccounts.Api.UnitTests.Controllers.TransferConnectionsControllerTests
{
Expand All @@ -15,9 +16,11 @@ public class WhenIGetTransferConnections
{
private TransferConnectionsController _controller;
private Mock<IMediator> _mediator;
private Mock<IHashingService> _hashingService;
private GetTransferConnectionsResponse _response;
private IEnumerable<TransferConnection> _transferConnections;
private string _hashedAccountId;
private readonly string _hashedAccountId = "GF3XWP";
private readonly int _accountId = 123;

[SetUp]
public void Arrange()
Expand All @@ -27,13 +30,15 @@ public void Arrange()
_transferConnections = new List<TransferConnection>();
_response = new GetTransferConnectionsResponse { TransferConnections = _transferConnections };

_hashedAccountId = "GF3XWP";
_hashingService = new Mock<IHashingService>();
_hashingService.Setup(x => x.HashValue(_accountId)).Returns(_hashedAccountId);

_mediator.Setup(
m => m.SendAsync(
It.Is<GetTransferConnectionsQuery>(q => q.HashedAccountId.Equals(_hashedAccountId))))
.ReturnsAsync(_response);

_controller = new TransferConnectionsController(_mediator.Object);
_controller = new TransferConnectionsController(_mediator.Object, _hashingService.Object);
}

[Test]
Expand All @@ -46,6 +51,16 @@ public async Task ThenAGetTransferConnectionsQueryShouldBeSent()
Times.Once);
}

[Test]
public async Task ThenAGetTransferConnectionsQueryShouldBeSentWithHashedId()
{
await _controller.GetTransferConnections(_accountId);

_mediator.Verify(
m => m.SendAsync(It.Is<GetTransferConnectionsQuery>(q => q.HashedAccountId.Equals(_hashedAccountId))),
Times.Once);
}

[Test]
public async Task ThenShouldReturnTransferConnections()
{
Expand All @@ -54,5 +69,14 @@ public async Task ThenShouldReturnTransferConnections()
Assert.That(result, Is.Not.Null);
Assert.That(result.Content, Is.SameAs(_transferConnections));
}

[Test]
public async Task ThenShouldReturnTransferConnectionsForInternal()
{
var result = await _controller.GetTransferConnections(_accountId) as OkNegotiatedContentResult<IEnumerable<TransferConnection>>;

Assert.That(result, Is.Not.Null);
Assert.That(result.Content, Is.SameAs(_transferConnections));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@
using MediatR;
using SFA.DAS.EmployerAccounts.Api.Attributes;
using SFA.DAS.EmployerAccounts.Queries.GetTransferConnections;
using SFA.DAS.HashingService;

namespace SFA.DAS.EmployerAccounts.Api.Controllers
{
[ApiAuthorize(Roles = "ReadUserAccounts")]
[RoutePrefix("api/accounts/{hashedAccountId}/transfers/connections")]
[RoutePrefix("api/accounts")]
public class TransferConnectionsController : ApiController
{
private readonly IMediator _mediator;
private readonly IHashingService _hashingService;

public TransferConnectionsController(IMediator mediator)
public TransferConnectionsController(IMediator mediator, IHashingService hashingService)
{
_mediator = mediator;
_hashingService = hashingService;
}
[Route]

[Route("{hashedAccountId}/transfers/connections")]
public async Task<IHttpActionResult> GetTransferConnections(string hashedAccountId)
{
var response = await _mediator.SendAsync( new GetTransferConnectionsQuery{ HashedAccountId = hashedAccountId});
return Ok(response.TransferConnections);
}

[Route("internal/{accountId}/transfers/connections")]
public async Task<IHttpActionResult> GetTransferConnections(long accountId)
{
var hashedAccountId = _hashingService.HashValue(accountId);

var response = await _mediator.SendAsync(new GetTransferConnectionsQuery { HashedAccountId = hashedAccountId });
return Ok(response.TransferConnections);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public async Task ThenTheValuesAreReturnedInTheResponseFromTheRequestForAllOrgan
var actual = await _orchestrator.GetOrganisationAgreements(AccountLegalEntityHashedId);

//Assert
Assert.IsNotNull(actual.Data.Any());
Assert.IsNotNull(actual.Data.Agreements.Any());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public async Task<ActionResult> WhenDoYouWantToView(int? choice, string agreemen
public async Task<ActionResult> ViewAllAgreements(string hashedAccountId, string accountLegalEntityHashedId)
{
var model = await _orchestrator.GetOrganisationAgreements(accountLegalEntityHashedId);
return View(model);
return View(model.Data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@ public static class ControllerConstants
public const string ApproveOrRejectApprentice = "ApproveOrRejectApprentice";
public const string ViewApprenticeBeforeApprove = "ViewApprenticeBeforeApprove";
public const string ViewAllAgreementActionName = "ViewAllAgreements";
public const string InsetText = "Inset";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,30 +320,34 @@ public virtual async Task<OrchestratorResponse<ConfirmOrganisationToRemoveViewMo
return response;
}

public virtual async Task<OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>> GetOrganisationAgreements(string accountLegalEntityHashedId)
public virtual async Task<OrchestratorResponse<OrganisationAgreementsViewModel>> GetOrganisationAgreements(string accountLegalEntityHashedId)
{
var response = new OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>();
var response = new OrchestratorResponse<OrganisationAgreementsViewModel>();

try
{
var result = await _mediator.SendAsync(new GetOrganisationAgreementsRequest
{
AccountLegalEntityHashedId = accountLegalEntityHashedId
});

response.Data = _mapper.Map<ICollection<EmployerAgreementDto>, ICollection<OrganisationAgreementViewModel>>(result.Agreements);

response.Data = new OrganisationAgreementsViewModel
{
AgreementId = accountLegalEntityHashedId,
Agreements = _mapper.Map<ICollection<EmployerAgreementDto>, ICollection<OrganisationAgreementViewModel>>(result.Agreements)
};
}
catch (InvalidRequestException ex)
{
return new OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>
return new OrchestratorResponse<OrganisationAgreementsViewModel>
{
Status = HttpStatusCode.BadRequest,
Exception = ex
};
}
catch (UnauthorizedAccessException)
{
return new OrchestratorResponse<ICollection<OrganisationAgreementViewModel>>
return new OrchestratorResponse<OrganisationAgreementsViewModel>
{
Status = HttpStatusCode.Unauthorized
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@
<Compile Include="Models\AccountContext.cs" />
<Compile Include="Models\ReturnUrlModel.cs" />
<Compile Include="Models\HashedAccountIdModel.cs" />
<Compile Include="ViewModels\OrganisationAgreementsViewModel.cs" />
<Compile Include="ViewModels\TermsAndConditionsNewViewModel.cs" />
<Compile Include="ViewModels\TriageViewModel.cs" />
<Compile Include="OrchestratorResponse.cs" />
Expand Down Expand Up @@ -864,8 +865,6 @@
<Content Include="Views\EmployerTeam\SingleApprenticeshipReadyForReview.cshtml" />
<Content Include="Views\EmployerTeam\SingleApprenticeshipContinueWithProvider.cshtml" />
<Content Include="Views\EmployerAgreement\ViewAllAgreements.cshtml" />
<Content Include="Views\Shared\_AcceptedAgreement.cshtml" />
<Content Include="Views\Shared\_NotAcceptedAgreement.cshtml" />
<Content Include="Views\EmployerAgreement\CannotRemoveOrganisation.cshtml" />
<Content Include="Views\EmployerTeam\Empty.cshtml" />
<Content Include="Views\EmployerAgreement\AcceptedEmployerAgreement.cshtml" />
Expand All @@ -875,6 +874,8 @@
<Content Include="Views\Shared\_Agreement_v6.cshtml" />
<Content Include="Views\SearchOrganisation\ConfirmOrganisationDetails.cshtml" />
<Content Include="Views\Home\TermsAndConditions.cshtml" />
<Content Include="Views\EmployerAgreement\_AwaitingAcceptance.cshtml" />
<Content Include="Views\EmployerAgreement\_AcceptedAgreement.cshtml" />
<Content Include="Views\Home\TermsAndConditionsOverview.cshtml" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,5 @@ public class OrganisationAgreementViewModel

public string AccountLegalEntityPublicHashedId => AccountLegalEntity.PublicHashedId;
public string SignedDateText => SignedDate.HasValue ? SignedDate.Value.ToString("dd MMMM yyyy") : "";

public string GetAgreementTabListId => $"#v{Template.VersionNumber}-agreement";
public string GetAgreementTabPanelId => $"v{Template.VersionNumber}-agreement";
}
}
Loading

0 comments on commit 2f25ac2

Please sign in to comment.