Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
fix/samplecollection (#96)
Browse files Browse the repository at this point in the history
* Fixed Sample Collection naming

* fix/return correct sc

Return the correct SC

* Apply suggestions from code review

Co-authored-by: Felix Dittrich <[email protected]>
  • Loading branch information
mschulte-tsi and f11h authored May 27, 2021
1 parent c6982cf commit 8fe4191
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public ResponseEntity<TestResultResponse> result(
@RequestBody @Valid TestResultRequest request
) {
log.info("Received test result request from app.");
TestResult result = testResultService.getOrCreate(request.getId(),false);

TestResult result = testResultService.getOrCreate(request.getId(), false, null);
return ResponseEntity.ok(new TestResultResponse()
.setTestResult(result.getResult(), result.getSc())
);
Expand Down Expand Up @@ -115,7 +116,7 @@ public ResponseEntity<TestResultResponse> quickTestResult(
@RequestBody @Valid TestResultRequest request
) {
log.info("Received test result request from Quicktest.");
TestResult result = testResultService.getOrCreate(request.getId(),true);
TestResult result = testResultService.getOrCreate(request.getId(), true, request.getSc());
return ResponseEntity.ok(new TestResultResponse()
.setTestResult(result.getResult()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ public TestResult toModel(TestResultEntity entity) {
* @return the mapped entity from model
*/
public TestResultEntity toEntity(TestResult model) {
if (model.getSc() == null) {
model.setSampleCollection(LocalDateTime.now().toEpochSecond(ZoneOffset.UTC));
}
return new TestResultEntity()
.setResult(model.getResult())
.setResultId(model.getId())
.setResultDate(LocalDateTime.now());
.setResultDate(LocalDateTime.ofEpochSecond(model.getSc(), 0, ZoneOffset.UTC));
}

/**
Expand Down Expand Up @@ -106,7 +109,7 @@ public TestResult createOrUpdate(final TestResult result) {
* @param id the test result id
* @return the test result
*/
public TestResult getOrCreate(final String id, boolean quicktest) {
public TestResult getOrCreate(final String id, boolean quicktest, Long sc) {
try {
TestResultEntity entity = testResultRepository.findByResultId(id)
.orElseGet(() -> {
Expand All @@ -119,7 +122,11 @@ public TestResult getOrCreate(final String id, boolean quicktest) {
resultEntity.setResult(TestResultEntity.Result.PENDING.ordinal());
resultEntity.setResultId(id);
}
resultEntity.setResultDate(LocalDateTime.now());
if (sc == null) {
resultEntity.setResultDate(LocalDateTime.now());
} else {
resultEntity.setResultDate(LocalDateTime.ofEpochSecond(sc, 0, ZoneOffset.UTC));
}
return testResultRepository.save(resultEntity);
});
return toModel(entity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void insertOrUpdate() {
Assert.assertNotNull(create);
Assert.assertEquals(result, create.getResult());
// get
TestResult get = testResultService.getOrCreate(id,false);
TestResult get = testResultService.getOrCreate(id, false, 0L);
Assert.assertNotNull(get);
Assert.assertEquals(result, get.getResult());
}
Expand All @@ -102,7 +102,7 @@ public void insertAndUpdate() {
Assert.assertNotNull(create);
Assert.assertEquals(resultCreate, create.getResult());
// get
TestResult get = testResultService.getOrCreate(id,false);
TestResult get = testResultService.getOrCreate(id, false, 0L);
Assert.assertNotNull(get);
Assert.assertEquals(resultCreate, get.getResult());
// update
Expand All @@ -113,7 +113,7 @@ public void insertAndUpdate() {
Assert.assertNotNull(update);
Assert.assertEquals(resultUpdate, update.getResult());
// get
get = testResultService.getOrCreate(id,false);
get = testResultService.getOrCreate(id, false, 0L);
Assert.assertNotNull(get);
Assert.assertEquals(resultUpdate, get.getResult());
}
Expand All @@ -124,7 +124,7 @@ public void getOrCreate() {
String id = "a".repeat(64);
Integer result = 0;
// get
TestResult get = testResultService.getOrCreate(id,false);
TestResult get = testResultService.getOrCreate(id, false, 0L);
Assert.assertNotNull(get);
Assert.assertEquals(result, get.getResult());
}
Expand Down

0 comments on commit 8fe4191

Please sign in to comment.