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

Appman 1292 cache add apprentice journey #539

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
sonar cloud fixes
  • Loading branch information
ogrwill committed Dec 11, 2024
commit 59c3d75abeaee34c211018d17e9efb25cee04e46
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using SFA.DAS.EmployerCommitmentsV2.Web.Extensions;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Cohort;
using SFA.DAS.EmployerCommitmentsV2.Web.Models.Shared;
using SFA.DAS.EmployerCommitmentsV2.Web.RouteValues;
using SFA.DAS.EmployerUrlHelper;
using SFA.DAS.Encoding;
using SFA.DAS.Http;
Expand Down Expand Up @@ -127,9 +128,9 @@ public async Task<IActionResult> Delete([FromServices] IAuthenticationService au
if (viewModel.ConfirmDeletion == true)
{
await _commitmentsApiClient.DeleteCohort(viewModel.CohortId, authenticationService.UserInfo, CancellationToken.None);
return RedirectToAction("Review", new { viewModel.CohortReference, viewModel.AccountHashedId });
return RedirectToAction(RouteNames.CohortReview, new { viewModel.CohortReference, viewModel.AccountHashedId });
}
return RedirectToAction("Details", new { viewModel.CohortReference, viewModel.AccountHashedId });
return RedirectToAction(RouteNames.CohortDetails, new { viewModel.CohortReference, viewModel.AccountHashedId });
}

[HttpGet]
Expand Down Expand Up @@ -182,7 +183,6 @@ public async Task<IActionResult> SelectProvider(Guid addApprenticeshipCacheKey)

var viewModel = await _modelMapper.Map<SelectProviderViewModel>(cacheModel);

//cacheModel.Origin = viewModel.Origin;
await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return View(viewModel);
Expand All @@ -201,14 +201,14 @@ public async Task<IActionResult> SelectProvider(SelectProviderViewModel request)
cacheModel.ProviderId = long.Parse(request.ProviderId);
await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return RedirectToAction("ConfirmProvider", new { cacheModel.AccountHashedId, cacheModel.CacheKey });
return RedirectToAction(RouteNames.CohortConfirmProvider, new { cacheModel.AccountHashedId, cacheModel.CacheKey });
}
catch (RestHttpClientException ex)
{
if (ex.StatusCode == HttpStatusCode.NotFound)
{
ModelState.AddModelError(nameof(request.ProviderId), "Select a training provider");
return RedirectToAction("SelectProvider", new { request.AccountHashedId, request.AddApprenticeshipCacheKey });
return RedirectToAction(RouteNames.CohortSelectProvider, new { request.AccountHashedId, request.AddApprenticeshipCacheKey });
}

_logger.LogError(ex, "Failed '{ControllerName)}.{ActionName}'", nameof(CohortController), nameof(SelectProvider));
Expand Down Expand Up @@ -237,10 +237,10 @@ public IActionResult ConfirmProvider(ConfirmProviderViewModel model)
{
if (model.UseThisProvider.Value)
{
return RedirectToAction("assign", new { model.AccountHashedId, model.AddApprenticeshipCacheKey });
return RedirectToAction(RouteNames.CohortAssign, new { model.AccountHashedId, model.AddApprenticeshipCacheKey });
}

return RedirectToAction("SelectProvider", new { model.AccountHashedId, model.AddApprenticeshipCacheKey });
return RedirectToAction(RouteNames.CohortSelectProvider, new { model.AccountHashedId, model.AddApprenticeshipCacheKey });
}

[Route("add/assign")]
Expand Down Expand Up @@ -286,7 +286,7 @@ public async Task<IActionResult> Assign(AssignViewModel model)
model.EncodedPledgeApplicationId,
model.AddApprenticeshipCacheKey
};
return RedirectToAction("Apprentice", "Cohort", routeValues);
return RedirectToAction(RouteNames.CohortApprentice, "Cohort", routeValues);
case WhoIsAddingApprentices.Provider:
var request = await _modelMapper.Map<CreateCohortWithOtherPartyRequest>(model);
var response = await _commitmentsApiClient.CreateCohort(request);
Expand All @@ -306,7 +306,7 @@ public async Task<IActionResult> Apprentice(ApprenticeRequest request)
cacheModel.StartMonthYear = request.StartMonthYear;
await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return RedirectToAction(nameof(SelectCourse), new { cacheModel.AccountHashedId, cacheModel.CacheKey });
return RedirectToAction(RouteNames.CohortSelectCourse, new { cacheModel.AccountHashedId, cacheModel.CacheKey });
}

[HttpGet]
Expand All @@ -316,7 +316,7 @@ public async Task<IActionResult> SelectCourse(Guid addApprenticeshipCacheKey)
var cacheModel = await GetAddApprenticeshipCacheModelFromCache(addApprenticeshipCacheKey);

var selectCourseViewModel = await _modelMapper.Map<SelectCourseViewModel>(cacheModel);
return View("SelectCourse", selectCourseViewModel);
return View(RouteNames.CohortSelectCourse, selectCourseViewModel);
}

[HttpPost]
Expand All @@ -327,11 +327,11 @@ public async Task<IActionResult> SelectCourse(SelectCourseViewModel model)
cacheModel.CourseCode = model.CourseCode;
await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return RedirectToAction(nameof(SelectDeliveryModel), new { cacheModel.AccountHashedId, cacheModel.CacheKey });
return RedirectToAction(RouteNames.CohortSelectDeliveryModel, new { cacheModel.AccountHashedId, cacheModel.CacheKey });
}

[HttpGet]
[ActionName(nameof(SelectDeliveryModel))]
[ActionName(RouteNames.CohortSelectDeliveryModel)]
[Route("add/select-delivery-model")]
public async Task<IActionResult> SelectDeliveryModel(ApprenticeRequest request)
{
Expand All @@ -346,7 +346,7 @@ public async Task<IActionResult> SelectDeliveryModel(ApprenticeRequest request)
{
await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return View("SelectDeliveryModel", model);
return View(RouteNames.CohortSelectDeliveryModel, model);
}

cacheModel.DeliveryModel = model.DeliveryModels.FirstOrDefault();
Expand Down Expand Up @@ -384,10 +384,10 @@ public async Task<IActionResult> AddDraftApprenticeship(Guid addApprenticeshipCa
var model = await _modelMapper.Map<ApprenticeViewModel>(cacheModel);

cacheModel.LegalEntityName = model.LegalEntityName;
//cacheModel.ProviderName = model.ProviderName;

await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return View("Apprentice", model);
return View(RouteNames.CohortApprentice, model);
}

[HttpPost]
Expand All @@ -402,7 +402,7 @@ public async Task<IActionResult> AddDraftApprenticeshipOrRoute(string changeCour

await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return RedirectToAction(changeCourse == "Edit" ? nameof(SelectCourse) : nameof(SelectDeliveryModel),
return RedirectToAction(changeCourse == "Edit" ? RouteNames.CohortSelectCourse : RouteNames.CohortSelectDeliveryModel,
new { cacheModel.AccountHashedId, cacheModel.CacheKey });
}

Expand All @@ -427,7 +427,7 @@ public async Task<IActionResult> SaveDraftApprenticeship(ApprenticeViewModel mod
return RedirectToAction("SelectOption", "DraftApprenticeship", new { model.AccountHashedId, newCohort.CohortReference, draftApprenticeshipHashedId });
}

return RedirectToAction("Details", new { model.AccountHashedId, newCohort.CohortReference });
return RedirectToAction(RouteNames.CohortDetails, new { model.AccountHashedId, newCohort.CohortReference });
}

[Authorize(Policy = nameof(PolicyNames.AccessCohort))]
Expand All @@ -448,7 +448,7 @@ public async Task<IActionResult> Finished(FinishedRequest request)
}

[HttpGet]
[Route("review", Name = "Review")]
[Route(RouteNames.CohortReview, Name = RouteNames.CohortReview)]
[Route("")]
public async Task<IActionResult> Review(CohortsByAccountRequest request)
{
Expand Down Expand Up @@ -516,7 +516,7 @@ public async Task<IActionResult> SelectTransferConnection(Guid addApprenticeship
cacheModel.TransferSenderId = string.Empty;
await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return RedirectToAction("SelectLegalEntity", new { cacheModel.AccountHashedId, cacheModel.CacheKey });
return RedirectToAction(RouteNames.CohortSelectLegalEntity, new { cacheModel.AccountHashedId, cacheModel.CacheKey });
}

[HttpPost]
Expand All @@ -531,7 +531,7 @@ public async Task<IActionResult> SetTransferConnection(SelectTransferConnectionV
cacheModel.TransferSenderId = transferConnectionCode;
await StoreAddApprenticeshipCacheModelInCache(cacheModel, cacheModel.CacheKey);

return RedirectToAction("SelectLegalEntity", new { selectedTransferConnection.AccountHashedId, cacheModel.CacheKey });
return RedirectToAction(RouteNames.CohortSelectLegalEntity, new { selectedTransferConnection.AccountHashedId, cacheModel.CacheKey });
}

[HttpGet]
Expand Down Expand Up @@ -568,7 +568,7 @@ public async Task<IActionResult> SelectLegalEntity([FromRoute] string accountHas

if (hasSignedMinimumRequiredAgreementVersion)
{
return RedirectToAction("SelectProvider", new { cacheModel.AccountHashedId, cacheModel.CacheKey });
return RedirectToAction(RouteNames.CohortSelectProvider, new { cacheModel.AccountHashedId, cacheModel.CacheKey });
}

var model = new LegalEntitySignedAgreementViewModel
Expand All @@ -581,7 +581,7 @@ public async Task<IActionResult> SelectLegalEntity([FromRoute] string accountHas
AccountLegalEntityHashedId = cacheModel.AccountLegalEntityHashedId
};

return RedirectToAction("AgreementNotSigned", model.CloneBaseValues());
return RedirectToAction(RouteNames.CohortAgreementNotSigned, model.CloneBaseValues());

}

Expand All @@ -599,7 +599,7 @@ public async Task<ActionResult> SetLegalEntity(SelectLegalEntityViewModel select

if (response.HasSignedMinimumRequiredAgreementVersion)
{
return RedirectToAction("SelectProvider", new { cacheModel.AccountHashedId, cacheModel.CacheKey });
return RedirectToAction(RouteNames.CohortSelectProvider, new { cacheModel.AccountHashedId, cacheModel.CacheKey });
}

var model = new LegalEntitySignedAgreementViewModel
Expand All @@ -612,11 +612,11 @@ public async Task<ActionResult> SetLegalEntity(SelectLegalEntityViewModel select
EncodedPledgeApplicationId = selectedLegalEntity.EncodedPledgeApplicationId
};

return RedirectToAction("AgreementNotSigned", model.CloneBaseValues());
return RedirectToAction(RouteNames.CohortAgreementNotSigned, model.CloneBaseValues());
}

[HttpGet]
[Route("AgreementNotSigned")]
[Route(RouteNames.CohortAgreementNotSigned)]
public async Task<ActionResult> AgreementNotSigned(LegalEntitySignedAgreementViewModel viewModel)
{
var response = await _modelMapper.Map<AgreementNotSignedViewModel>(viewModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class AddApprenticeshipCacheModel : ICacheModel
public Guid CacheKey { get; set; }
public string AccountHashedId { get; set; }
public long AccountId { get; set; }
// public string TransferConnectionCode { get; set; }
public string CohortRef { get; set; }
public string EncodedPledgeApplicationId { get; set; } = null;
public string AccountLegalEntityHashedId { get; set; }
Expand All @@ -19,8 +18,6 @@ public class AddApprenticeshipCacheModel : ICacheModel
public string StartMonthYear { get; set; }
public string TransferSenderId { get; set; }
public long ProviderId { get; set; }
// public string ProviderName { get; set; }
//public Origin Origin { get; set; }
public DeliveryModel? DeliveryModel { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
Expand Down
11 changes: 11 additions & 0 deletions src/SFA.DAS.EmployerCommitmentsV2.Web/RouteValues/RouteNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,15 @@ public static class RouteNames
public const string WhyStopApprenticeship = "why-stop-apprenticeship";
public const string ApprenticeshipNeverStarted = "apprenticeship-never-started";
public const string ApprenticeshipHasNotEnded = "apprenticeship-not-ended";

public const string CohortSelectProvider = "SelectProvider";
public const string CohortConfirmProvider = "ConfirmProvider";
public const string CohortReview = "Review";
public const string CohortDetails = "Details";
public const string CohortAssign = "assign";
public const string CohortSelectCourse = "SelectCourse";
public const string CohortSelectDeliveryModel = "SelectDeliveryModel";
public const string CohortApprentice = "Apprentice";
public const string CohortSelectLegalEntity = "SelectLegalEntity";
public const string CohortAgreementNotSigned = "AgreementNotSigned";
}