Skip to content

Commit

Permalink
459419 Transpose pom and org data
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbenjamin-defra committed Nov 6, 2024
1 parent adf34c8 commit 766d533
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using EPR.Calculator.API.Data.DataModels;
using EPR.Calculator.API.Dtos;
using EPR.Calculator.API.Services;
using EPR.Calculator.API.Tests.Controllers;
using EPR.Calculator.API.Wrapper;
Expand Down Expand Up @@ -38,7 +39,9 @@ public void Transpose_Should_Return_Correct_Producer_Detail()
#pragma warning disable CS8604 // Possible null reference argument.
var service = new TransposePomAndOrgDataService(dbContext);
#pragma warning restore CS8604 // Possible null reference argument.
service.Transpose(3);

var resultsRequestDto = new CalcResultsRequestDto { RunId = 3 };
service.Transpose(resultsRequestDto);

var producerDetail = dbContext.ProducerDetail.FirstOrDefault();
Assert.IsNotNull(producerDetail);
Expand Down Expand Up @@ -78,7 +81,9 @@ public void Transpose_Should_Return_Correct_Producer_Reported_Material()
#pragma warning disable CS8604 // Possible null reference argument.
var service = new TransposePomAndOrgDataService(dbContext);
#pragma warning restore CS8604 // Possible null reference argument.
service.Transpose(3);

var resultsRequestDto = new CalcResultsRequestDto { RunId = 3 };
service.Transpose(resultsRequestDto);

var producerReportedMaterial = dbContext.ProducerReportedMaterial.FirstOrDefault();
Assert.IsNotNull(producerReportedMaterial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public IActionResult UpdateRpdStatus([FromBody] UpdateRpdStatus request)
[Route("prepareCalcResults")]
public IActionResult PrepareCalcResults([FromBody] CalcResultsRequestDto resultsRequestDto)
{
this.transposePomAndOrgDataService.Transpose(resultsRequestDto.RunId);
this.transposePomAndOrgDataService.Transpose(resultsRequestDto);
var results = this.builder.Build(resultsRequestDto);
this.exporter.Export(results);
return new ObjectResult(null) { StatusCode = StatusCodes.Status201Created };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace EPR.Calculator.API.Services
using EPR.Calculator.API.Dtos;

namespace EPR.Calculator.API.Services
{
public interface ITransposePomAndOrgDataService
{
public void Transpose(int runId);
public void Transpose(CalcResultsRequestDto resultsRequestDto);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EPR.Calculator.API.Data;
using EPR.Calculator.API.Data.DataModels;
using EPR.Calculator.API.Wrapper;
using EPR.Calculator.API.Dtos;

namespace EPR.Calculator.API.Services
{
Expand All @@ -14,11 +14,11 @@ public TransposePomAndOrgDataService(ApplicationDBContext context)
this.context = context;
}

public void Transpose(int runId)
public void Transpose(CalcResultsRequestDto resultsRequestDto)
{
var materials = this.context.Material.ToList();

var calculatorRun = this.context.CalculatorRuns.Single(cr => cr.Id == runId);
var calculatorRun = this.context.CalculatorRuns.Single(cr => cr.Id == resultsRequestDto.RunId);

if (calculatorRun.CalculatorRunPomDataMasterId != null)
{
Expand Down Expand Up @@ -48,7 +48,7 @@ public void Transpose(int runId)
{
var producerDetail = new ProducerDetail
{
CalculatorRunId = runId,
CalculatorRunId = resultsRequestDto.RunId,
ProducerId = pom.OrganisationId.Value,
SubsidiaryId = pom.SubsidaryId,
ProducerName = producerName,
Expand Down

0 comments on commit 766d533

Please sign in to comment.