Skip to content

Commit

Permalink
Fixed PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hortha committed Nov 27, 2023
1 parent d487d15 commit ed140da
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>trscli</AssemblyName>
<UserSecretsId>3e48f8dd-cdfd-4528-a94e-a2cf2b4381ac</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ public async Task<dfeta_specialism[]> Execute(GetAllSpecialismsQuery query, IOrg
var filter = new FilterExpression(LogicalOperator.And);
filter.AddCondition(dfeta_specialism.Fields.StateCode, ConditionOperator.Equal, (int)dfeta_specialismState.Active);
var valueFilter = new FilterExpression(LogicalOperator.Or);
valueFilter.AddCondition(dfeta_specialism.Fields.dfeta_Value, ConditionOperator.Equal, "Hearing");
valueFilter.AddCondition(dfeta_specialism.Fields.dfeta_Value, ConditionOperator.Equal, "Multi-Sensory");
valueFilter.AddCondition(dfeta_specialism.Fields.dfeta_Value, ConditionOperator.Equal, "Visual");
valueFilter.AddCondition(dfeta_specialism.Fields.dfeta_Value, ConditionOperator.In, "Hearing", "Multi-Sensory", "Visual");
filter.AddFilter(valueFilter);

var queryExpression = new QueryExpression
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
if not exists (select 1 from information_schema.columns where table_name = 'dfeta_qualification' and column_name = 'dfeta_mq_status')
alter table dfeta_qualification add dfeta_mq_status int
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<None Remove="Dqt\Services\DqtReporting\Migrations\0012_FixProgrammeTypeCasing.sql" />
<None Remove="Dqt\Services\DqtReporting\Migrations\0013_PreviousNameTransactionId.sql" />
<None Remove="Dqt\Services\DqtReporting\Migrations\0014_Contact_dfeta_allowidsigninwithprohibitions.sql" />
<None Remove="Dqt\Services\DqtReporting\Migrations\0015_dfeta_qualification_dfeta_mq_status.sql" />
</ItemGroup>

<ItemGroup>
Expand All @@ -38,6 +39,7 @@
<EmbeddedResource Include="Dqt\Services\DqtReporting\Migrations\0012_FixProgrammeTypeCasing.sql" />
<EmbeddedResource Include="Dqt\Services\DqtReporting\Migrations\0013_PreviousNameTransactionId.sql" />
<EmbeddedResource Include="Dqt\Services\DqtReporting\Migrations\0014_Contact_dfeta_allowidsigninwithprohibitions.sql" />
<EmbeddedResource Include="Dqt\Services\DqtReporting\Migrations\0015_dfeta_qualification_dfeta_mq_status.sql" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,57 @@ namespace TeachingRecordSystem.SupportUi.Infrastructure.Filters;

public class CheckPersonExistsFilter : IAsyncResourceFilter, IOrderedFilter
{
private readonly bool _requireQts;

public int Order => -200;

public CheckPersonExistsFilter(bool requireQts = false)
{
_requireQts = requireQts;
}

public async Task OnResourceExecutionAsync(ResourceExecutingContext context, ResourceExecutionDelegate next)
{
var personId = context.RouteData.Values["personId"] as string;
if (personId is null)
{
var personIdQueryParameters = context.HttpContext.Request.Query["personId"];
if (personIdQueryParameters.Count == 1)
{
personId = personIdQueryParameters[0];
}
}

if (personId is not null)
{
var crmQueryDispatcher = context.HttpContext.RequestServices.GetRequiredService<ICrmQueryDispatcher>();
var person = await crmQueryDispatcher.ExecuteQuery(new GetContactDetailByIdQuery(Guid.Parse(personId), new ColumnSet(Contact.Fields.Id)));
var person = await crmQueryDispatcher.ExecuteQuery(
new GetContactDetailByIdQuery(
Guid.Parse(personId),
new ColumnSet(
Contact.Fields.Id,
Contact.Fields.FirstName,
Contact.Fields.MiddleName,
Contact.Fields.LastName,
Contact.Fields.dfeta_StatedFirstName,
Contact.Fields.dfeta_StatedLastName,
Contact.Fields.dfeta_StatedMiddleName,
Contact.Fields.dfeta_QTSDate)));
if (person is null)
{
context.Result = new NotFoundResult();
return;
}
else
{
if (_requireQts && person.Contact.dfeta_QTSDate is null)
{
context.Result = new BadRequestResult();
return;
}
}

context.HttpContext.Items["CurrentPersonDetail"] = person;
}

await next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,14 @@ public async Task<IActionResult> OnPostCancel()

public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
var person = await _crmQueryDispatcher.ExecuteQuery(
new GetContactDetailByIdQuery(
PersonId,
new ColumnSet(
Contact.Fields.FirstName,
Contact.Fields.MiddleName,
Contact.Fields.LastName,
Contact.Fields.dfeta_StatedFirstName,
Contact.Fields.dfeta_StatedLastName,
Contact.Fields.dfeta_StatedMiddleName,
Contact.Fields.dfeta_QTSDate)));
if (person is null)
{
context.Result = NotFound();
return;
}

if (person.Contact.dfeta_QTSDate is null)
{
context.Result = BadRequest();
return;
}
var personDetail = context.HttpContext.Items["CurrentPersonDetail"] as ContactDetail;

if (!JourneyInstance!.State.IsComplete)
{
context.Result = Redirect(_linkGenerator.MqAddProvider(PersonId, JourneyInstance.InstanceId));
}

PersonName = person.Contact.ResolveFullName(includeMiddleName: false);
PersonName = personDetail!.Contact.ResolveFullName(includeMiddleName: false);
MqEstablishment = await _referenceDataCache.GetMqEstablishmentByValue(JourneyInstance!.State.MqEstablishmentValue!);
Specialism = await _referenceDataCache.GetSpecialismByValue(JourneyInstance!.State.SpecialismValue!);
StartDate = JourneyInstance!.State.StartDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeachingRecordSystem.Core.Dqt.Models;
using TeachingRecordSystem.Core.Dqt.Queries;

namespace TeachingRecordSystem.SupportUi.Pages.Mqs.AddMq;

[Journey(JourneyNames.AddMq), ActivatesJourney, RequireJourneyInstance]
public class ProviderModel : PageModel
{
private readonly ICrmQueryDispatcher _crmQueryDispatcher;
private readonly ReferenceDataCache _referenceDataCache;
private readonly TrsLinkGenerator _linkGenerator;

public ProviderModel(
ICrmQueryDispatcher crmQueryDispatcher,
ReferenceDataCache referenceDataCache,
TrsLinkGenerator linkGenerator)
{
_crmQueryDispatcher = crmQueryDispatcher;
_referenceDataCache = referenceDataCache;
_linkGenerator = linkGenerator;
}
Expand Down Expand Up @@ -56,35 +52,14 @@ public async Task<IActionResult> OnPost()

public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
var person = await _crmQueryDispatcher.ExecuteQuery(
new GetContactDetailByIdQuery(
PersonId,
new ColumnSet(
Contact.Fields.FirstName,
Contact.Fields.MiddleName,
Contact.Fields.LastName,
Contact.Fields.dfeta_StatedFirstName,
Contact.Fields.dfeta_StatedLastName,
Contact.Fields.dfeta_StatedMiddleName,
Contact.Fields.dfeta_QTSDate)));
if (person is null)
{
context.Result = NotFound();
return;
}

if (person.Contact.dfeta_QTSDate is null)
{
context.Result = BadRequest();
return;
}
var personDetail = context.HttpContext.Items["CurrentPersonDetail"] as ContactDetail;

var establishments = await _referenceDataCache.GetMqEstablishments();
MqEstablishments = establishments
.OrderBy(e => e.dfeta_name)
.ToArray();

PersonName = person.Contact.ResolveFullName(includeMiddleName: false);
PersonName = personDetail!.Contact.ResolveFullName(includeMiddleName: false);
MqEstablishmentValue ??= JourneyInstance!.State.MqEstablishmentValue;

await next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeachingRecordSystem.Core.Dqt.Models;
using TeachingRecordSystem.Core.Dqt.Queries;

namespace TeachingRecordSystem.SupportUi.Pages.Mqs.AddMq;

[Journey(JourneyNames.AddMq), RequireJourneyInstance]
public class ResultModel : PageModel
{
private readonly ICrmQueryDispatcher _crmQueryDispatcher;
private readonly TrsLinkGenerator _linkGenerator;

public ResultModel(
ICrmQueryDispatcher crmQueryDispatcher,
TrsLinkGenerator linkGenerator)
{
_crmQueryDispatcher = crmQueryDispatcher;
_linkGenerator = linkGenerator;
}

Expand Down Expand Up @@ -64,30 +60,9 @@ public async Task<IActionResult> OnPost()

public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
var person = await _crmQueryDispatcher.ExecuteQuery(
new GetContactDetailByIdQuery(
PersonId,
new ColumnSet(
Contact.Fields.FirstName,
Contact.Fields.MiddleName,
Contact.Fields.LastName,
Contact.Fields.dfeta_StatedFirstName,
Contact.Fields.dfeta_StatedLastName,
Contact.Fields.dfeta_StatedMiddleName,
Contact.Fields.dfeta_QTSDate)));
if (person is null)
{
context.Result = NotFound();
return;
}

if (person.Contact.dfeta_QTSDate is null)
{
context.Result = BadRequest();
return;
}
var personDetail = context.HttpContext.Items["CurrentPersonDetail"] as ContactDetail;

PersonName = person.Contact.ResolveFullName(includeMiddleName: false);
PersonName = personDetail!.Contact.ResolveFullName(includeMiddleName: false);
Result ??= JourneyInstance!.State.Result;
EndDate ??= JourneyInstance!.State.EndDate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeachingRecordSystem.Core.Dqt.Models;
using TeachingRecordSystem.Core.Dqt.Queries;

namespace TeachingRecordSystem.SupportUi.Pages.Mqs.AddMq;

[Journey(JourneyNames.AddMq), RequireJourneyInstance]
public class SpecialismModel : PageModel
{
private readonly ICrmQueryDispatcher _crmQueryDispatcher;
private readonly ReferenceDataCache _referenceDataCache;
private readonly TrsLinkGenerator _linkGenerator;

public SpecialismModel(
ICrmQueryDispatcher crmQueryDispatcher,
ReferenceDataCache referenceDataCache,
TrsLinkGenerator linkGenerator)
{
_crmQueryDispatcher = crmQueryDispatcher;
_referenceDataCache = referenceDataCache;
_linkGenerator = linkGenerator;
}
Expand Down Expand Up @@ -54,35 +50,14 @@ public async Task<IActionResult> OnPost()

public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
var person = await _crmQueryDispatcher.ExecuteQuery(
new GetContactDetailByIdQuery(
PersonId,
new ColumnSet(
Contact.Fields.FirstName,
Contact.Fields.MiddleName,
Contact.Fields.LastName,
Contact.Fields.dfeta_StatedFirstName,
Contact.Fields.dfeta_StatedLastName,
Contact.Fields.dfeta_StatedMiddleName,
Contact.Fields.dfeta_QTSDate)));
if (person is null)
{
context.Result = NotFound();
return;
}

if (person.Contact.dfeta_QTSDate is null)
{
context.Result = BadRequest();
return;
}
var personDetail = context.HttpContext.Items["CurrentPersonDetail"] as ContactDetail;

var specialisms = await _referenceDataCache.GetSpecialisms();
Specialisms = specialisms
.OrderBy(e => e.dfeta_name)
.ToArray();

PersonName = person.Contact.ResolveFullName(includeMiddleName: false);
PersonName = personDetail!.Contact.ResolveFullName(includeMiddleName: false);
SpecialismValue ??= JourneyInstance!.State.SpecialismValue;

await next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
using TeachingRecordSystem.Core.Dqt.Models;
using TeachingRecordSystem.Core.Dqt.Queries;

namespace TeachingRecordSystem.SupportUi.Pages.Mqs.AddMq;

[Journey(JourneyNames.AddMq), RequireJourneyInstance]
public class StartDateModel : PageModel
{
private readonly ICrmQueryDispatcher _crmQueryDispatcher;
private readonly TrsLinkGenerator _linkGenerator;

public StartDateModel(
ICrmQueryDispatcher crmQueryDispatcher,
TrsLinkGenerator linkGenerator)
{
_crmQueryDispatcher = crmQueryDispatcher;
_linkGenerator = linkGenerator;
}

Expand Down Expand Up @@ -51,30 +47,9 @@ public async Task<IActionResult> OnPost()

public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
var person = await _crmQueryDispatcher.ExecuteQuery(
new GetContactDetailByIdQuery(
PersonId,
new ColumnSet(
Contact.Fields.FirstName,
Contact.Fields.MiddleName,
Contact.Fields.LastName,
Contact.Fields.dfeta_StatedFirstName,
Contact.Fields.dfeta_StatedLastName,
Contact.Fields.dfeta_StatedMiddleName,
Contact.Fields.dfeta_QTSDate)));
if (person is null)
{
context.Result = NotFound();
return;
}

if (person.Contact.dfeta_QTSDate is null)
{
context.Result = BadRequest();
return;
}
var personDetail = context.HttpContext.Items["CurrentPersonDetail"] as ContactDetail;

PersonName = person.Contact.ResolveFullName(includeMiddleName: false);
PersonName = personDetail!.Contact.ResolveFullName(includeMiddleName: false);
StartDate ??= JourneyInstance!.State.StartDate;

await next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
{
model.Filters.Add(new CheckPersonExistsFilter());
});
options.Conventions.AddFolderApplicationModelConvention(
"/Mqs",
model =>
{
model.Filters.Add(new CheckPersonExistsFilter());
});
})
.AddMvcOptions(options =>
{
Expand Down
Loading

0 comments on commit ed140da

Please sign in to comment.