Skip to content

Commit

Permalink
Merge pull request #619 from DFE-Digital/feature/191269-change-grant-…
Browse files Browse the repository at this point in the history
…comms

Returning A2B application `CreatedOn` Information
  • Loading branch information
mshakirdfe authored Dec 6, 2024
2 parents fc67ec9 + c86cbba commit 94ce10a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public record ApplicationServiceModel(
DateTime? ApplicationSubmittedDate,
string? ApplicationReference,
Guid EntityId,
DateTime? DeletedAt);
DateTime? DeletedAt,
DateTime? CreatedOn);
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal static ApplicationServiceModel MapFromDomain(this IApplication applicat
application.ApplicationSubmittedDate,
application.ApplicationReference,
application.EntityId,
application.DeletedAt);
application.DeletedAt,
application.CreatedOn);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task ParametersValid___ApplicationCreated()
applicationCreateRequestModel.Contributor.Role,
applicationCreateRequestModel.Contributor.OtherRoleName) },
new List<ApplicationSchoolServiceModel>(),
null, null, null, id.ToString(), actualApplication.EntityId, null);
null, null, null, id.ToString(), actualApplication.EntityId, null, null);

Assert.Equivalent(expectedApplication, actualApplication);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,30 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Dfe.Academies.Academisation.Service.Commands.Application;
using Dfe.Academies.Academisation.Service.Commands.ConversionProject;
using Dfe.Academies.Academisation.IService.ServiceModels.Legacy.ProjectAggregate;

namespace Dfe.Academies.Academisation.WebApi.Controllers
{
[Route("application")]
[ApiController]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public class ApplicationController : ControllerBase
public class ApplicationController(
IApplicationQueryService applicationQueryService,
ITrustQueryService trustQueryService,
IMediator mediator,
ILogger<ApplicationController> logger
) : ControllerBase
{
private const string GetRouteName = "GetApplication";
private readonly IApplicationQueryService _applicationQueryService;
private readonly ITrustQueryService _trustQueryService;
private readonly IMediator _mediator;
private readonly ILogger<ApplicationController> _logger;

public ApplicationController(
IApplicationQueryService applicationQueryService,
ITrustQueryService trustQueryService,
IMediator mediator,
ILogger<ApplicationController> logger
)
{
// need guard clauses on these check for null
_applicationQueryService = applicationQueryService;
_trustQueryService = trustQueryService;
_mediator = mediator;
_logger = logger;
}

[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[HttpPost]
public async Task<ActionResult<ApplicationServiceModel>> Post([FromBody] ApplicationCreateCommand command, CancellationToken cancellationToken)
{
_logger.LogInformation($"Creating application using post endpoint with contributor: {command?.Contributor?.EmailAddress}");
var result = await _mediator.Send(command, cancellationToken).ConfigureAwait(false);
logger.LogInformation($"Creating application using post endpoint with contributor: {command?.Contributor?.EmailAddress}");

var result = await mediator.Send(command!, cancellationToken).ConfigureAwait(false);

return result switch
{
Expand All @@ -56,30 +43,30 @@ public async Task<ActionResult<ApplicationServiceModel>> Post([FromBody] Applica
[HttpGet("{id}", Name = GetRouteName)]
public async Task<ActionResult<ApplicationServiceModel>> Get(int id)
{
_logger.LogInformation($"Getting application, id: {id}");
logger.LogInformation($"Getting application, id: {id}");

var result = await _applicationQueryService.GetById(id);
var result = await applicationQueryService.GetById(id);
return result is null ? NotFound() : Ok(result);
}

[HttpGet("contributor/{email}", Name = "List")]
public async Task<ActionResult<IList<ApplicationServiceModel>>> ListByUser(string email)
{
var result = await _applicationQueryService.GetByUserEmail(email);
var result = await applicationQueryService.GetByUserEmail(email);
return Ok(result);
}

[HttpGet("{applicationReference}/applicationReference", Name = "Get")]
public async Task<ActionResult<ApplicationServiceModel>> Get(string applicationReference)
{
var result = await _applicationQueryService.GetByApplicationReference(applicationReference);
var result = await applicationQueryService.GetByApplicationReference(applicationReference);
return result != null ? Ok(result) : NotFound();
}

[HttpPut("{id}", Name = "Update")]
public async Task<ActionResult> Update(int id, [FromBody] ApplicationUpdateCommand command, CancellationToken cancellationToken)
{
_logger.LogInformation($"Updating application: {command.ApplicationId} with values: {command.ToString()}");
logger.LogInformation($"Updating application: {command.ApplicationId} with values: {command.ToString()}");
CommandResult? result = null;

// this should probably be a pipeline validator
Expand All @@ -91,7 +78,7 @@ public async Task<ActionResult> Update(int id, [FromBody] ApplicationUpdateComma
});
}
else {
result = await _mediator.Send(command, cancellationToken).ConfigureAwait(false);
result = await mediator.Send(command, cancellationToken).ConfigureAwait(false);
}

return result switch
Expand All @@ -106,8 +93,8 @@ public async Task<ActionResult> Update(int id, [FromBody] ApplicationUpdateComma
[HttpPut("{applicationId}/join-trust", Name = "SetJoinTrustDetails")]
public async Task<ActionResult> SetJoinTrustDetails(int applicationId, [FromBody] SetJoinTrustDetailsCommand command, CancellationToken cancellationToken)
{
_logger.LogInformation($"Setting join trust information for application: {applicationId} with details: {command.ToString()}");
var result = await _mediator.Send(command with { applicationId = applicationId}, cancellationToken).ConfigureAwait(false);
logger.LogInformation($"Setting join trust information for application: {applicationId} with details: {command.ToString()}");
var result = await mediator.Send(command with { applicationId = applicationId}, cancellationToken).ConfigureAwait(false);

return result switch
{
Expand All @@ -122,8 +109,8 @@ public async Task<ActionResult> SetJoinTrustDetails(int applicationId, [FromBody
[HttpPut("{applicationId}/form-trust", Name = "SetFormTrustDetails")]
public async Task<ActionResult> SetFormTrustDetails(int applicationId, [FromBody] SetFormTrustDetailsCommand command, CancellationToken cancellationToken)
{
_logger.LogInformation($"Setting form trust information for application: {applicationId} with details: {command.ToString()}");
var result = await _mediator.Send(command with { applicationId = applicationId }, cancellationToken).ConfigureAwait(false);
logger.LogInformation($"Setting form trust information for application: {applicationId} with details: {command.ToString()}");
var result = await mediator.Send(command with { applicationId = applicationId }, cancellationToken).ConfigureAwait(false);

return result switch
{
Expand All @@ -137,8 +124,8 @@ public async Task<ActionResult> SetFormTrustDetails(int applicationId, [FromBody
[HttpPost("{applicationId}/form-trust/key-person", Name = "AddKeyPerson")]
public async Task<ActionResult> AddKeyPerson(int applicationId, [FromBody] CreateTrustKeyPersonCommand command, CancellationToken cancellationToken)
{
_logger.LogInformation($"Adding key people to application: {applicationId} with details: {command.ToString()}");
var result = await _mediator.Send(command with { ApplicationId = applicationId }, cancellationToken).ConfigureAwait(false);
logger.LogInformation($"Adding key people to application: {applicationId} with details: {command.ToString()}");
var result = await mediator.Send(command with { ApplicationId = applicationId }, cancellationToken).ConfigureAwait(false);

return result switch
{
Expand All @@ -152,8 +139,8 @@ public async Task<ActionResult> AddKeyPerson(int applicationId, [FromBody] Creat
[HttpPut("{applicationId}/form-trust/key-person/{keyPersonId}", Name = "UpdateKeyPerson")]
public async Task<ActionResult> UpdateKeyPerson(int applicationId, int keyPersonId, [FromBody] UpdateTrustKeyPersonCommand command, CancellationToken cancellationToken)
{
_logger.LogInformation($"Updating key people to application: {applicationId} with details: {command.ToString()}");
var result = await _mediator.Send(command with { ApplicationId = applicationId, KeyPersonId = keyPersonId }, cancellationToken).ConfigureAwait(false);
logger.LogInformation($"Updating key people to application: {applicationId} with details: {command.ToString()}");
var result = await mediator.Send(command with { ApplicationId = applicationId, KeyPersonId = keyPersonId }, cancellationToken).ConfigureAwait(false);

return result switch
{
Expand All @@ -167,8 +154,8 @@ public async Task<ActionResult> UpdateKeyPerson(int applicationId, int keyPerson
[HttpDelete("{applicationId}/form-trust/key-person/{keyPersonId}", Name = "DeleteKeyPerson")]
public async Task<ActionResult> DeleteKeyPerson(int applicationId, int keyPersonId, CancellationToken cancellationToken)
{
_logger.LogInformation($"Deleting key person: {keyPersonId} in application: {applicationId}");
var result = await _mediator.Send(new DeleteTrustKeyPersonCommand(applicationId, keyPersonId), cancellationToken).ConfigureAwait(false);
logger.LogInformation($"Deleting key person: {keyPersonId} in application: {applicationId}");
var result = await mediator.Send(new DeleteTrustKeyPersonCommand(applicationId, keyPersonId), cancellationToken).ConfigureAwait(false);

return result switch
{
Expand All @@ -182,8 +169,8 @@ public async Task<ActionResult> DeleteKeyPerson(int applicationId, int keyPerson
[HttpDelete("{applicationId}/form-trust/school/{urn}", Name = "DeleteSchool")]
public async Task<ActionResult> DeleteSchool(int applicationId, int urn, CancellationToken cancellationToken)
{
_logger.LogInformation($"Deleting school: {urn} in application: {applicationId}");
var result = await _mediator.Send(new DeleteSchoolCommand(applicationId, urn), cancellationToken).ConfigureAwait(false);
logger.LogInformation($"Deleting school: {urn} in application: {applicationId}");
var result = await mediator.Send(new DeleteSchoolCommand(applicationId, urn), cancellationToken).ConfigureAwait(false);

return result switch
{
Expand All @@ -197,22 +184,22 @@ public async Task<ActionResult> DeleteSchool(int applicationId, int urn, Cancell
[HttpGet("{applicationId}/form-trust/key-person/", Name = "GetKeyPeople")]
public async Task<ActionResult<List<object>>> GetKeyPeople(int applicationId, CancellationToken cancellationToken)
{
var result = await _trustQueryService.GetAllTrustKeyPeople(applicationId);
var result = await trustQueryService.GetAllTrustKeyPeople(applicationId);
return result is null ? NotFound() : Ok(result);
}

[HttpGet("{applicationId}/form-trust/key-person/{keyPersonId}", Name = "GetKeyPerson")]
public async Task<ActionResult<object>> GetKeyPerson(int applicationId, int keyPersonId, CancellationToken cancellationToken)
{
var result = await _trustQueryService.GetTrustKeyPerson(applicationId, keyPersonId);
var result = await trustQueryService.GetTrustKeyPerson(applicationId, keyPersonId);
return result is null ? NotFound() : Ok(result);
}

[HttpPost("{applicationId:int}/submit", Name = "Submit")]
public async Task<ActionResult> Submit(int applicationId)
{
_logger.LogInformation($"Submitting application: {applicationId}");
var result = await _mediator.Send(new ApplicationSubmitCommand(applicationId)).ConfigureAwait(false);
logger.LogInformation($"Submitting application: {applicationId}");
var result = await mediator.Send(new ApplicationSubmitCommand(applicationId)).ConfigureAwait(false);

return result switch
{
Expand All @@ -229,16 +216,16 @@ public async Task<ActionResult> Submit(int applicationId)
[HttpGet("all", Name = "All")]
public async Task<ActionResult<List<ApplicationSchoolSharepointServiceModel>>> GetAll()
{
var result = await _applicationQueryService.GetAllApplications();
var result = await applicationQueryService.GetAllApplications();
return Ok(result);
}

[HttpDelete("{applicationId}/delete-application", Name = "DeleteApplication")]
public async Task<ActionResult> DeleteApplication(int applicationId)
{
_logger.LogInformation($"Deleting application: {applicationId}");
logger.LogInformation($"Deleting application: {applicationId}");

var result = await _mediator.Send(new ApplicationDeleteCommand(applicationId)).ConfigureAwait(false);
var result = await mediator.Send(new ApplicationDeleteCommand(applicationId)).ConfigureAwait(false);

return result switch
{
Expand Down

0 comments on commit 94ce10a

Please sign in to comment.