diff --git a/.github/workflows/ci-dockerfile.yml b/.github/workflows/ci-dockerfile.yml index cdf701e..33147ef 100644 --- a/.github/workflows/ci-dockerfile.yml +++ b/.github/workflows/ci-dockerfile.yml @@ -1,5 +1,6 @@ name: ci-dockerfile on: + workflow_dispatch: push: branches: - master diff --git a/src/main/java/app/coronawarn/testresult/TestResultController.java b/src/main/java/app/coronawarn/testresult/TestResultController.java index 7fefe54..20eed2d 100644 --- a/src/main/java/app/coronawarn/testresult/TestResultController.java +++ b/src/main/java/app/coronawarn/testresult/TestResultController.java @@ -71,7 +71,8 @@ public ResponseEntity result( log.info("Received test result request from app."); TestResult result = testResultService.getOrCreate(request.getId(),false); return ResponseEntity.ok(new TestResultResponse() - .setTestResult(result.getResult())); + .setTestResult(result.getResult(), result.getSc()) + ); } /** diff --git a/src/main/java/app/coronawarn/testresult/model/QuickTestResult.java b/src/main/java/app/coronawarn/testresult/model/QuickTestResult.java index 81df0d6..791abde 100644 --- a/src/main/java/app/coronawarn/testresult/model/QuickTestResult.java +++ b/src/main/java/app/coronawarn/testresult/model/QuickTestResult.java @@ -62,6 +62,11 @@ public class QuickTestResult { @NotNull private Integer result; + /** + * Timestamp of the SampleCollection (sc). + */ + private Long sc; + public QuickTestResult setId(String id) { this.id = id; return this; @@ -71,4 +76,9 @@ public QuickTestResult setResult(Integer result) { this.result = result; return this; } + + public QuickTestResult setSampleCollection(Long sc) { + this.sc = sc; + return this; + } } diff --git a/src/main/java/app/coronawarn/testresult/model/TestResult.java b/src/main/java/app/coronawarn/testresult/model/TestResult.java index 4655987..a43dbaf 100644 --- a/src/main/java/app/coronawarn/testresult/model/TestResult.java +++ b/src/main/java/app/coronawarn/testresult/model/TestResult.java @@ -67,6 +67,11 @@ public class TestResult { @NotNull private Integer result; + /** + * Timestamp of the SampleCollection (sc). + */ + private Long sc; + public TestResult setId(String id) { this.id = id; return this; @@ -76,4 +81,9 @@ public TestResult setResult(Integer result) { this.result = result; return this; } + + public TestResult setSampleCollection(Long sc) { + this.sc = sc; + return this; + } } diff --git a/src/main/java/app/coronawarn/testresult/model/TestResultRequest.java b/src/main/java/app/coronawarn/testresult/model/TestResultRequest.java index 6889aae..59e032a 100644 --- a/src/main/java/app/coronawarn/testresult/model/TestResultRequest.java +++ b/src/main/java/app/coronawarn/testresult/model/TestResultRequest.java @@ -46,8 +46,26 @@ public class TestResultRequest { @Pattern(regexp = "^([A-Fa-f0-9]{2}){32}$") private String id; + /** + * Timestamp of the SampleCollection (sc). + */ + private Long sc; + + /** + * Default constructor with sc null. + */ public TestResultRequest setId(String id) { this.id = id; + this.sc = null; + return this; + } + + /** + * All args constructor with sc. + */ + public TestResultRequest setId(String id, Long sc) { + this.id = id; + this.sc = sc; return this; } } diff --git a/src/main/java/app/coronawarn/testresult/model/TestResultResponse.java b/src/main/java/app/coronawarn/testresult/model/TestResultResponse.java index 222d12f..71d71b5 100644 --- a/src/main/java/app/coronawarn/testresult/model/TestResultResponse.java +++ b/src/main/java/app/coronawarn/testresult/model/TestResultResponse.java @@ -21,7 +21,9 @@ package app.coronawarn.testresult.model; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.v3.oas.annotations.media.Schema; +import javax.annotation.Nullable; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; @@ -38,6 +40,7 @@ @Getter @ToString @EqualsAndHashCode +@JsonInclude(JsonInclude.Include.NON_NULL) public class TestResultResponse { /** @@ -57,8 +60,26 @@ public class TestResultResponse { @Max(9) private Integer testResult; + /** + * Timestamp of the SampleCollection (sc). + */ + private Long cs; + + /** + * Default constructor with sc null. + */ public TestResultResponse setTestResult(Integer testResult) { this.testResult = testResult; + this.cs = null; + return this; + } + + /** + * All args constructor with sc. + */ + public TestResultResponse setTestResult(Integer testResult,Long resultDate) { + this.testResult = testResult; + this.cs = resultDate; return this; } } diff --git a/src/main/java/app/coronawarn/testresult/service/TestResultService.java b/src/main/java/app/coronawarn/testresult/service/TestResultService.java index e49c7c7..90aa5c8 100644 --- a/src/main/java/app/coronawarn/testresult/service/TestResultService.java +++ b/src/main/java/app/coronawarn/testresult/service/TestResultService.java @@ -27,6 +27,8 @@ import app.coronawarn.testresult.model.QuickTestResult; import app.coronawarn.testresult.model.TestResult; import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; import java.util.Optional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -50,7 +52,8 @@ public class TestResultService { public TestResult toModel(TestResultEntity entity) { return new TestResult() .setId(entity.getResultId()) - .setResult(entity.getResult()); + .setResult(entity.getResult()) + .setSampleCollection(entity.getResultDate().atZone(ZoneId.of("UTC")).toEpochSecond()); } /** diff --git a/src/test/java/app/coronawarn/testresult/TestResultControllerTest.java b/src/test/java/app/coronawarn/testresult/TestResultControllerTest.java index 0155d02..ab0c347 100644 --- a/src/test/java/app/coronawarn/testresult/TestResultControllerTest.java +++ b/src/test/java/app/coronawarn/testresult/TestResultControllerTest.java @@ -171,8 +171,57 @@ public void notExistingTestResultShouldReturnOk() throws Exception { } + @Test + public void quickInsertValidWithCsShouldReturnNoContent() throws Exception { + // data + String id = "b".repeat(64); + Integer result = 5; + // create + QuickTestResultList valid = new QuickTestResultList(); + valid.setTestResults( Collections.singletonList( + new QuickTestResult().setId(id).setResult(result).setSampleCollection(System.currentTimeMillis()) + )); + mockMvc.perform(MockMvcRequestBuilders + .post("/api/v1/quicktest/results") + .accept(MediaType.APPLICATION_JSON_VALUE) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .content(objectMapper.writeValueAsString(valid))) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isNoContent()); + } + @Test + public void quickInsertValidWithCsShouldReturnNoContentAndQueryResult() throws Exception { + // data + String id = "b".repeat(64); + Integer result = 5; + // create + QuickTestResultList valid = new QuickTestResultList(); + valid.setTestResults(Collections.singletonList( + new QuickTestResult().setId(id).setResult(result).setSampleCollection(System.currentTimeMillis()) + )); + mockMvc.perform(MockMvcRequestBuilders + .post("/api/v1/quicktest/results") + .accept(MediaType.APPLICATION_JSON_VALUE) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .content(objectMapper.writeValueAsString(valid))) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isNoContent()); + TestResultRequest request = new TestResultRequest() + .setId(id); + mockMvc.perform(MockMvcRequestBuilders + .post("/api/v1/app/result") + .accept(MediaType.APPLICATION_JSON_VALUE) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .content(objectMapper.writeValueAsString(request))) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andReturn() + .getResponse() + .getContentAsString() + .contains("cs"); + } @Test public void quickInsertValidShouldReturnNoContent() throws Exception {