-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,612 additions
and
8 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
TeachingRecordSystem/src/TeachingRecordSystem.Api/Properties/StringResources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Core/Operations/GetQTLS.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Microsoft.Xrm.Sdk.Query; | ||
using TeachingRecordSystem.Api.V3.Core.SharedModels; | ||
using TeachingRecordSystem.Core.Dqt; | ||
using TeachingRecordSystem.Core.Dqt.Models; | ||
using TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
namespace TeachingRecordSystem.Api.V3.Core.Operations; | ||
|
||
public record GetQTLSCommand(string Trn); | ||
|
||
public class GetQTLSHandler(ICrmQueryDispatcher _crmQueryDispatcher) | ||
{ | ||
public async Task<QTLSInfo?> Handle(GetQTLSCommand command) | ||
{ | ||
var contact = (await _crmQueryDispatcher.ExecuteQuery( | ||
new GetActiveContactByTrnQuery( | ||
command.Trn, | ||
new ColumnSet( | ||
Contact.Fields.dfeta_TRN, | ||
Contact.Fields.dfeta_qtlsdate | ||
) | ||
) | ||
))!; | ||
|
||
if (contact is null) | ||
{ | ||
return null; | ||
} | ||
|
||
return new QTLSInfo() | ||
{ | ||
Trn = command.Trn, | ||
QTSDate = contact.dfeta_qtlsdate.ToDateOnlyWithDqtBstFix(isLocalTime: true), | ||
}; | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Core/Operations/SetQTLS.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Microsoft.Xrm.Sdk.Query; | ||
using TeachingRecordSystem.Api.V3.Core.SharedModels; | ||
using TeachingRecordSystem.Api.Validation; | ||
using TeachingRecordSystem.Core.Dqt; | ||
using TeachingRecordSystem.Core.Dqt.Models; | ||
using TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
namespace TeachingRecordSystem.Api.V3.Core.Operations; | ||
|
||
|
||
public record SetQTLSCommand(string Trn, DateOnly? QTSDate); | ||
|
||
public class SetQTLSHandler(ICrmQueryDispatcher _crmQueryDispatcher) | ||
{ | ||
public async Task<QTLSInfo?> Handle(SetQTLSCommand command) | ||
{ | ||
var contact = (await _crmQueryDispatcher.ExecuteQuery( | ||
new GetActiveContactByTrnQuery( | ||
command.Trn, | ||
new ColumnSet( | ||
Contact.Fields.dfeta_TRN, | ||
Contact.Fields.dfeta_InductionStatus, | ||
Contact.Fields.dfeta_qtlsdate | ||
) | ||
) | ||
))!; | ||
|
||
if (contact == null) | ||
{ | ||
return null; | ||
} | ||
|
||
if (!CanSetQTLSDate(contact.dfeta_InductionStatus, contact.dfeta_qtlsdate, command.QTSDate)) | ||
{ | ||
var _ = await _crmQueryDispatcher.ExecuteQuery( | ||
new CreateReviewTaskQuery() | ||
{ | ||
TeacherId = contact.Id, | ||
Category = "Unable to set QTLSDate", | ||
Description = $"Unable to set QTLSDate {command.QTSDate}", | ||
Subject = "Notification for SET QTLS data collections team" | ||
} | ||
); | ||
|
||
throw new ErrorException(ErrorRegistry.UnableToUpdateQTLSDate()); | ||
} | ||
|
||
await _crmQueryDispatcher.ExecuteQuery( | ||
new SetQTLSDateQuery(contact.Id, command.QTSDate))!; | ||
|
||
contact = (await _crmQueryDispatcher.ExecuteQuery( | ||
new GetActiveContactByTrnQuery( | ||
command.Trn, | ||
new ColumnSet( | ||
Contact.Fields.dfeta_TRN, | ||
Contact.Fields.dfeta_qtlsdate | ||
) | ||
) | ||
))!; | ||
|
||
return new QTLSInfo() | ||
{ | ||
Trn = command.Trn, | ||
QTSDate = contact.dfeta_qtlsdate.ToDateOnlyWithDqtBstFix(isLocalTime: true) | ||
}; | ||
} | ||
|
||
private bool CanSetQTLSDate(dfeta_InductionStatus? inductionStatus, DateTime? existingQtlsdate, DateOnly? incomingQtlsDate) => | ||
inductionStatus switch | ||
{ | ||
dfeta_InductionStatus.InProgress when !existingQtlsdate.HasValue && incomingQtlsDate.HasValue => false, | ||
dfeta_InductionStatus.InductionExtended when !existingQtlsdate.HasValue && incomingQtlsDate.HasValue => false, | ||
dfeta_InductionStatus.Fail => false, | ||
dfeta_InductionStatus.FailedinWales when !existingQtlsdate.HasValue && incomingQtlsDate.HasValue => false, | ||
dfeta_InductionStatus.FailedinWales when existingQtlsdate.HasValue && incomingQtlsDate.HasValue => false, | ||
dfeta_InductionStatus.Exempt when existingQtlsdate.HasValue => false, | ||
_ when existingQtlsdate.HasValue && incomingQtlsDate.HasValue && incomingQtlsDate.Value != existingQtlsdate.ToDateOnlyWithDqtBstFix(isLocalTime: false) => false, | ||
_ => true | ||
}; | ||
} | ||
|
7 changes: 7 additions & 0 deletions
7
TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/Core/SharedModels/QTLSInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace TeachingRecordSystem.Api.V3.Core.SharedModels; | ||
|
||
public record QTLSInfo | ||
{ | ||
public required DateOnly? QTSDate { get; init; } | ||
public required string Trn { get; init; } | ||
} |
73 changes: 73 additions & 0 deletions
73
...ngRecordSystem/src/TeachingRecordSystem.Api/V3/V20240307/Controllers/PersonsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using Mapster; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
using TeachingRecordSystem.Api.V3.Core.Operations; | ||
using TeachingRecordSystem.Api.V3.Core.SharedModels; | ||
using TeachingRecordSystem.Api.V3.VNext.Requests; | ||
|
||
namespace TeachingRecordSystem.Api.V3.V20240307.Controllers; | ||
|
||
[ApiController] | ||
[Route("persons")] | ||
[Authorize(Roles = ApiRoles.UpdatePerson)] | ||
public class PersonsController : ControllerBase | ||
{ | ||
private readonly IMediator _mediator; | ||
|
||
public PersonsController(IMediator mediator) | ||
{ | ||
_mediator = mediator; | ||
} | ||
|
||
|
||
[HttpPut("{trn}/qtls")] | ||
[SwaggerOperation( | ||
OperationId = "PutQTLS", | ||
Summary = "Sets QTLS status for a teacher", | ||
Description = "Sets QTLS status for a teacher.")] | ||
[ProducesResponseType(typeof(QTLSInfo), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] | ||
[MapError(10030, statusCode: StatusCodes.Status202Accepted)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> Put( | ||
[FromBody] SetQTLSRequest request, | ||
[FromServices] SetQTLSHandler handler) | ||
{ | ||
var command = new SetQTLSCommand(request.Trn!, request.QTSDate); | ||
var result = await handler.Handle(command); | ||
|
||
if (result is null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var response = result.Adapt<QTLSInfo>(); | ||
return Ok(response); | ||
} | ||
|
||
[HttpGet("{trn}/qtls")] | ||
[SwaggerOperation( | ||
OperationId = "GetQTLS", | ||
Summary = "Gets QTLS status for a teacher", | ||
Description = "Gets QTLS status for a teacher.")] | ||
[ProducesResponseType(typeof(QTLSInfo), StatusCodes.Status200OK)] | ||
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] | ||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> Get( | ||
[FromRoute] string trn, | ||
[FromServices] GetQTLSHandler handler) | ||
{ | ||
var command = new GetQTLSCommand(trn); | ||
var result = await handler.Handle(command); | ||
|
||
if (result is null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
var response = result.Adapt<QTLSInfo>(); | ||
return Ok(response); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
TeachingRecordSystem/src/TeachingRecordSystem.Api/V3/V20240307/Requests/SetQTLSRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace TeachingRecordSystem.Api.V3.VNext.Requests; | ||
|
||
public record SetQTLSRequest | ||
{ | ||
public required DateOnly? QTSDate { get; init; } | ||
|
||
[FromRoute] | ||
public string? Trn { get; set; } | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...rdSystem/src/TeachingRecordSystem.Api/V3/V20240307/Validators/SetQTLSSRequestValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using FluentValidation; | ||
using TeachingRecordSystem.Api.V3.VNext.Requests; | ||
|
||
namespace TeachingRecordSystem.Api.V3.VNext.Validators; | ||
|
||
public class SetQTLSSRequestValidator : AbstractValidator<SetQTLSRequest> | ||
{ | ||
public SetQTLSSRequestValidator(IClock clock) | ||
{ | ||
RuleFor(x => x.Trn) | ||
.Matches(@"^\d{7}$") | ||
.WithMessage(Properties.StringResources.ErrorMessages_TRNMustBe7Digits); | ||
|
||
RuleFor(x => x.QTSDate) | ||
.LessThanOrEqualTo(clock.Today) | ||
.WithMessage($"QTLS Date cannot be in the future."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/CreateReviewTaskQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace TeachingRecordSystem.Core.Dqt.Queries; | ||
public record CreateReviewTaskQuery : ICrmQuery<Guid> | ||
{ | ||
public required Guid TeacherId { get; set; } | ||
public required string Category { get; set; } | ||
public required string Subject { get; set; } | ||
public required string Description { get; set; } | ||
} |
3 changes: 3 additions & 0 deletions
3
TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/SetQTLSDateQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
public record SetQTLSDateQuery(Guid contactId, DateOnly? qtlsDate) : ICrmQuery<bool>; |
20 changes: 20 additions & 0 deletions
20
...ngRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/CreateReviewTaskHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using TeachingRecordSystem.Core.Dqt; | ||
using TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
public class CreateReviewTaskHandler : ICrmQueryHandler<CreateReviewTaskQuery, Guid> | ||
{ | ||
public async Task<Guid> Execute(CreateReviewTaskQuery query, IOrganizationServiceAsync organizationService) | ||
{ | ||
var crmTaskId = await organizationService.CreateAsync(new CrmTask() | ||
{ | ||
Id = Guid.NewGuid(), | ||
RegardingObjectId = query.TeacherId.ToEntityReference(Contact.EntityLogicalName), | ||
Category = query.Category, | ||
Subject = query.Subject, | ||
Description = query.Description | ||
}); | ||
|
||
return crmTaskId; | ||
} | ||
} |
Oops, something went wrong.