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

feat/add sample collection #94

Merged
merged 7 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-dockerfile.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: ci-dockerfile
on:
workflow_dispatch:
push:
branches:
- master
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public ResponseEntity<TestResultResponse> 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())
);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/app/coronawarn/testresult/model/QuickTestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -71,4 +76,9 @@ public QuickTestResult setResult(Integer result) {
this.result = result;
return this;
}

public QuickTestResult setSampleCollection(Long sc) {
this.sc = sc;
return this;
}
}
10 changes: 10 additions & 0 deletions src/main/java/app/coronawarn/testresult/model/TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -76,4 +81,9 @@ public TestResult setResult(Integer result) {
this.result = result;
return this;
}

public TestResult setSampleCollection(Long sc) {
this.sc = sc;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +40,7 @@
@Getter
@ToString
@EqualsAndHashCode
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TestResultResponse {

/**
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down