Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CathLass committed Dec 17, 2024
1 parent 38a1931 commit cf5ca36
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion TeachingRecordSystem/TeachingRecordSystem.sln
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeachingRecordSystem.Author
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "gen", "gen", "{5E273A79-2EA3-46CD-9049-769F880868FE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeachingRecordSystem.Api.Generator", "gen\TeachingRecordSystem.Api.Generator\TeachingRecordSystem.Api.Generator.csproj", "{7EA8C0A7-C149-4928-8E37-55D44976D765}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TeachingRecordSystem.Api.Generator", "gen\TeachingRecordSystem.Api.Generator\TeachingRecordSystem.Api.Generator.csproj", "{7EA8C0A7-C149-4928-8E37-55D44976D765}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static bool ValidateInductionData(
{
var requiresStartDate = status.RequiresStartDate();
var requiresCompletedDate = status.RequiresCompletedDate();
var requiresExemptionReason = status.RequiresExemptionReason();
var requiresExemptionReason = status.RequiresExemptionReasons();

if (requiresStartDate && startDate is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum InductionStatus
None = 0,
[InductionStatusInfo("required to complete", requiresStartDate: false, requiresCompletedDate: false)]
RequiredToComplete = 1,
[InductionStatusInfo("exempt", requiresStartDate: false, requiresCompletedDate: false, requiresExemptionReason: true)]
[InductionStatusInfo("exempt", requiresStartDate: false, requiresCompletedDate: false, requiresExemptionReasons: true)]
Exempt = 2,
[InductionStatusInfo("in progress", requiresStartDate: true, requiresCompletedDate: false)]
InProgress = 3,
Expand All @@ -35,7 +35,7 @@ public static class InductionStatusRegistry

public static bool RequiresCompletedDate(this InductionStatus status) => _info[status].RequiresCompletedDate;

public static bool RequiresExemptionReason(this InductionStatus status) => _info[status].RequiresExemptionReason;
public static bool RequiresExemptionReasons(this InductionStatus status) => _info[status].RequiresExemptionReasons;

public static InductionStatus ToInductionStatus(this dfeta_InductionStatus status) =>
ToInductionStatus((dfeta_InductionStatus?)status);
Expand Down Expand Up @@ -67,16 +67,16 @@ private static InductionStatusInfo GetInfo(InductionStatus status)
}
}

public sealed record InductionStatusInfo(InductionStatus Value, string Name, bool RequiresStartDate, bool RequiresCompletedDate, bool RequiresExemptionReason = false)
public sealed record InductionStatusInfo(InductionStatus Value, string Name, bool RequiresStartDate, bool RequiresCompletedDate, bool RequiresExemptionReasons = false)
{
public string Title => Name[0..1].ToUpper() + Name[1..];
}

[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
file sealed class InductionStatusInfoAttribute(string name, bool requiresStartDate, bool requiresCompletedDate, bool requiresExemptionReason = false) : Attribute
file sealed class InductionStatusInfoAttribute(string name, bool requiresStartDate, bool requiresCompletedDate, bool requiresExemptionReasons = false) : Attribute
{
public string Name => name;
public bool RequiresStartDate => requiresStartDate;
public bool RequiresCompletedDate => requiresCompletedDate;
public bool RequiresExemptionReason => requiresExemptionReason;
public bool RequiresExemptionReason => requiresExemptionReasons;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public CheckYourAnswersModel(TrsLinkGenerator linkGenerator) : base(linkGenerato
{
}

public string BackLink => PageLink(InductionJourneyPage.ChangeReason);
public string BackLink => PageLink(InductionJourneyPage.ChangeReasons);

public void OnGet()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ public abstract class CommonJourneyPage : PageModel
{
protected TrsLinkGenerator _linkGenerator;
public JourneyInstance<EditInductionState>? JourneyInstance { get; set; }
public virtual InductionStatus InductionStatus
{
get { return JourneyInstance!.State.InductionStatus; }
set { }
}
//public virtual InductionStatus InductionStatus
//{
// get { return JourneyInstance!.State.InductionStatus; }
// set { }
//}

[FromRoute]
public Guid PersonId { get; set; }
Expand All @@ -35,8 +35,8 @@ protected string PageLink(InductionJourneyPage? pageName)
InductionJourneyPage.CompletedDate => _linkGenerator.InductionEditCompletedDate(PersonId, JourneyInstance!.InstanceId),
InductionJourneyPage.ExemptionReason => _linkGenerator.InductionEditExemptionReason(PersonId, JourneyInstance!.InstanceId),
InductionJourneyPage.StartDate => _linkGenerator.InductionEditStartDate(PersonId, JourneyInstance!.InstanceId),
InductionJourneyPage.ChangeReason => _linkGenerator.InductionChangeReason(PersonId, JourneyInstance!.InstanceId),
InductionJourneyPage.CheckYourAnswers => _linkGenerator.InductionCheckYourAnswers(PersonId, JourneyInstance!.InstanceId),
InductionJourneyPage.ChangeReasons => _linkGenerator.InductionChangeReason(PersonId, JourneyInstance!.InstanceId),
InductionJourneyPage.CheckAnswers => _linkGenerator.InductionCheckYourAnswers(PersonId, JourneyInstance!.InstanceId),
_ => _linkGenerator.PersonInduction(PersonId)
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.EditInductio
[Journey(JourneyNames.EditInduction), ActivatesJourney, RequireJourneyInstance]
public class CompletedDateModel : CommonJourneyPage
{
public InductionJourneyPage NextPage => InductionJourneyPage.ChangeReason;
public InductionJourneyPage NextPage => InductionJourneyPage.ChangeReasons;
public string BackLink
{
// TODO - more logic needed when other routes to completed-date are added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EditInductionState : IRegisterJourney

public bool Initialized { get; set; }

public async Task EnsureInitializedAsync(TrsDbContext dbContext, Guid personId)
public async Task EnsureInitializedAsync(TrsDbContext dbContext, Guid personId, InductionJourneyPage startPage)
{
if (Initialized)
{
Expand All @@ -28,6 +28,10 @@ public async Task EnsureInitializedAsync(TrsDbContext dbContext, Guid personId)
var person = await dbContext.Persons
.SingleAsync(q => q.PersonId == personId);
InductionStatus = person!.InductionStatus;
if (JourneyStartPage == null)
{
JourneyStartPage = startPage;
}

Initialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.EditInductio
[Journey(JourneyNames.EditInduction), RequireJourneyInstance]
public class ExemptionReasonModel : CommonJourneyPage
{
public InductionJourneyPage NextPage => InductionJourneyPage.ChangeReason;
public InductionJourneyPage NextPage => InductionJourneyPage.ChangeReasons;
public string BackLink
{
// TODO - more logic needed when other routes to exemption reason are added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.EditInductio
[Journey(JourneyNames.EditInduction), RequireJourneyInstance]
public class InductionChangeReasonModel : CommonJourneyPage
{
public InductionJourneyPage NextPage => InductionJourneyPage.CheckYourAnswers;
public InductionStatus InductionStatus => JourneyInstance!.State.InductionStatus;
public InductionJourneyPage NextPage => InductionJourneyPage.CheckAnswers;
public string BackLink
{
get
Expand All @@ -14,7 +15,7 @@ public string BackLink
{
_ when InductionStatus.RequiresCompletedDate() => PageLink(InductionJourneyPage.CompletedDate),
_ when InductionStatus.RequiresStartDate() => PageLink(InductionJourneyPage.StartDate),
_ when InductionStatus.RequiresExemptionReason() => PageLink(InductionJourneyPage.ExemptionReason),
_ when InductionStatus.RequiresExemptionReasons() => PageLink(InductionJourneyPage.ExemptionReason),
_ => PageLink(InductionJourneyPage.Status),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public enum InductionJourneyPage
ExemptionReason,
StartDate,
CompletedDate,
ChangeReason,
CheckYourAnswers
ChangeReasons,
CheckAnswers
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ namespace TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.EditInductio
[Journey(JourneyNames.EditInduction), ActivatesJourney, RequireJourneyInstance]
public class StartDateModel : CommonJourneyPage
{
public InductionStatus InductionStatus => JourneyInstance!.State.InductionStatus;

public InductionJourneyPage NextPage
{
get
{
return InductionStatus.RequiresCompletedDate()
? InductionJourneyPage.CompletedDate
: InductionJourneyPage.ChangeReason;
: InductionJourneyPage.ChangeReasons;
}
}

Expand All @@ -31,7 +33,7 @@ public void OnGet()

public async Task<IActionResult> OnPostAsync()
{
InductionStatus = JourneyInstance!.State.InductionStatus;
//InductionStatus = JourneyInstance!.State.InductionStatus;
await JourneyInstance!.UpdateStateAsync(state =>
{
// TODO - store the start date
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@page "/persons/{PersonId}/edit-induction/status"
@model TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.EditInduction.StatusModel
@{
ViewBag.Title = "Edit status: " + Model.InductionStatus;
ViewBag.Title = "Edit status: " + Model.InductionStatus.GetName();
}

@section BeforeContent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ public class StatusModel : CommonJourneyPage
protected TrsDbContext _dbContext;

[BindProperty]
public override InductionStatus InductionStatus { get; set; }
public InductionStatus InductionStatus { get; set; }

public InductionJourneyPage NextPage
{
get
{
return InductionStatus switch
{
_ when InductionStatus.RequiresExemptionReason() => InductionJourneyPage.ExemptionReason,
_ when InductionStatus.RequiresExemptionReasons() => InductionJourneyPage.ExemptionReason,
_ when InductionStatus.RequiresStartDate() => InductionJourneyPage.StartDate,
_ => InductionJourneyPage.ChangeReason
_ => InductionJourneyPage.ChangeReasons
};
}
}
Expand All @@ -41,20 +41,15 @@ public async Task<IActionResult> OnPostAsync()
await JourneyInstance!.UpdateStateAsync(state =>
{
state.InductionStatus = InductionStatus;
if (state.JourneyStartPage == null)
{
state.JourneyStartPage = InductionJourneyPage.Status;
}
});

return Redirect(PageLink(NextPage));
}

public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
await JourneyInstance!.State.EnsureInitializedAsync(_dbContext, PersonId);
await JourneyInstance!.State.EnsureInitializedAsync(_dbContext, PersonId, InductionJourneyPage.Status);

await next();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ public async Task Post_RedirectsToExpectedPage(string fromPage, InductionStatus
{
// Arrange
var person = await TestData.CreatePersonAsync(
personBuilder => personBuilder
.WithInductionStatus(inductionBuilder => inductionBuilder
p => p
.WithQts()
.WithInductionStatus(i => i
.WithStatus(inductionStatus)));

var journeyInstance = await CreateJourneyInstanceAsync(
Expand Down Expand Up @@ -74,7 +75,7 @@ public async Task Post_RedirectsToExpectedPage(string fromPage, InductionStatus
public async Task Cancel_RedirectsToExpectedPage(string fromPage)
{
// Arrange
var person = await TestData.CreatePersonAsync();
var person = await TestData.CreatePersonAsync(p => p.WithQts());

var journeyInstance = await CreateJourneyInstanceAsync(
person.PersonId,
Expand Down Expand Up @@ -111,7 +112,7 @@ public async Task Post_PersistsBacklinkBreadcrumb(string page, InductionJourneyP
{
// Arrange
InductionStatus inductionStatus = InductionStatus.Passed;
var person = await TestData.CreatePersonAsync();
var person = await TestData.CreatePersonAsync(p => p.WithQts());

var journeyInstance = await CreateJourneyInstanceAsync(
person.PersonId,
Expand Down Expand Up @@ -154,7 +155,7 @@ public async Task Post_PersistsBacklinkBreadcrumb(string page, InductionJourneyP
public async Task FollowingRedirect_BacklinkContainsExpected(string fromPage, InductionStatus inductionStatus)
{
// Arrange
var person = await TestData.CreatePersonAsync();
var person = await TestData.CreatePersonAsync(p => p.WithQts());

var journeyInstance = await CreateJourneyInstanceAsync(
person.PersonId,
Expand Down

0 comments on commit cf5ca36

Please sign in to comment.