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

CON-5373 - Validation Payment Priority Issue #572

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json;
using SFA.DAS.CommitmentsV2.Api.Client;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
Expand All @@ -10,47 +11,47 @@ namespace SFA.DAS.EmployerCommitmentsV2.Web.Controllers;

[Authorize(Policy = nameof(PolicyNames.HasEmployerTransactorOwnerAccount))]
[Route("accounts/{accountHashedId}/apprentices/manage")]
public class PaymentOrderController : Controller
public class PaymentOrderController(
ICommitmentsApiClient commitmentsApiClient,
ILogger<PaymentOrderController> logger,
IModelMapper modelMapper)
: Controller
{
private readonly ICommitmentsApiClient _commitmentsApiClient;
private readonly ILogger<PaymentOrderController> _logger;
private readonly IModelMapper _modelMapper;

public PaymentOrderController(
ICommitmentsApiClient commitmentsApiClient,
ILogger<PaymentOrderController> logger,
IModelMapper modelMapper)
{
_commitmentsApiClient = commitmentsApiClient;
_logger = logger;
_modelMapper = modelMapper;
}

[HttpGet]
[Route("paymentorder", Name = "ProviderPaymentOrder")]
public async Task<ActionResult> ProviderPaymentOrder(PaymentOrderRequest request)
{
var viewModel = await _modelMapper.Map<PaymentOrderViewModel>(request);
var viewModel = await modelMapper.Map<PaymentOrderViewModel>(request);
return View(viewModel);
}

[Route("paymentorder")]
[HttpPost]
public async Task<IActionResult> ProviderPaymentOrder(PaymentOrderViewModel viewModel)
{
logger.LogInformation("ProviderPaymentOrderController.ProviderPaymentOrder POST called. Model: {Model}", JsonConvert.SerializeObject(viewModel));

try
{
var request = await _modelMapper.Map<UpdateProviderPaymentsPriorityRequest>(viewModel);
await _commitmentsApiClient.UpdateProviderPaymentsPriority(viewModel.AccountId, request);

return RedirectToAction(nameof(HomeController.Index), nameof(HomeController).ControllerName(), new { viewModel.AccountHashedId });
var request = await modelMapper.Map<UpdateProviderPaymentsPriorityRequest>(viewModel);

logger.LogInformation("ProviderPaymentOrderController.ProviderPaymentOrder request object after mapping: {Model}", JsonConvert.SerializeObject(request));

await commitmentsApiClient.UpdateProviderPaymentsPriority(viewModel.AccountId, request);

logger.LogInformation("ProviderPaymentOrderController.ProviderPaymentOrder completed save to commitmentsApiClient");
}
catch (Exception ex)
{
_logger.LogError(ex,
$"Failed to set payment order '{nameof(PaymentOrderController)}-{nameof(ProviderPaymentOrder)}'");
logger.LogError(ex, $"Failed to set payment order '{nameof(PaymentOrderController)}-{nameof(ProviderPaymentOrder)}'");

logger.LogInformation("ProviderPaymentOrderController.ProviderPaymentOrder caught in exception {Ex}, redirecting to error controller.", ex.ToString());

return RedirectToAction("Error", "Error");
}

return RedirectToAction("Error", "Error");

logger.LogInformation("ProviderPaymentOrderController.ProviderPaymentOrder Redirecting to HomeController.Index");

return RedirectToAction(nameof(HomeController.Index), nameof(HomeController).ControllerName(), new { viewModel.AccountHashedId });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
<PackageReference Include="SFA.DAS.Employer.Shared.UI" Version="17.1.131" />
<PackageReference Include="SFA.DAS.EmployerUrlHelper" Version="3.0.43" />
<PackageReference Include="SFA.DAS.InputValidation" Version="17.1.100" />
<PackageReference Include="SFA.DAS.Validation.Mvc" Version="6.0.31" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.1" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="WebEssentials.AspNetCore.CdnTagHelpers" Version="1.0.21" />
<PackageReference Include="SFA.DAS.Validation.Mvc" Version="6.0.30" />
<PackageReference Include="StackExchange.Redis" Version="2.8.24" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.12" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration;
using SFA.DAS.CommitmentsV2.Shared.Extensions;
using SFA.DAS.Employer.Shared.UI;
using SFA.DAS.EmployerCommitmentsV2.Configuration;
using SFA.DAS.EmployerCommitmentsV2.Web.Authorization;
using SFA.DAS.EmployerCommitmentsV2.Web.Filters;
using SFA.DAS.EmployerCommitmentsV2.Web.ModelBinding;
using SFA.DAS.EmployerCommitmentsV2.Web.Validators;
using SFA.DAS.Validation.Mvc.Extensions;

namespace SFA.DAS.EmployerCommitmentsV2.Web.ServiceRegistrations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<PackageReference Include="SFA.DAS.EmployerUrlHelper" Version="3.0.43" />
<PackageReference Include="SFA.DAS.Encoding" Version="1.1.76" />
<PackageReference Include="SFA.DAS.GovUK.Auth" Version="17.1.127" />
<PackageReference Include="SFA.DAS.Validation.Mvc" Version="6.0.31" />
<PackageReference Include="System.Formats.Asn1" Version="8.0.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.2.1" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="8.0.0" />
Expand Down