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

Commit d76756c

Browse files
Feat change endpoint (#90)
* changed endpoint to list * fixed tests cleaned pom * feat: resultstates_quicktest, value range lab results Co-authored-by: Andreas Scheibal <[email protected]>
1 parent 8887252 commit d76756c

7 files changed

Lines changed: 114 additions & 28 deletions

File tree

pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@
119119
<groupId>org.springframework.cloud</groupId>
120120
<artifactId>spring-cloud-starter-vault-config</artifactId>
121121
</dependency>
122-
<dependency>
123-
<groupId>org.springframework.boot</groupId>
124-
<artifactId>spring-boot-starter-validation</artifactId>
125-
</dependency>
126122
<dependency>
127123
<groupId>org.springframework.cloud</groupId>
128124
<artifactId>spring-cloud-starter-config</artifactId>

src/main/java/app/coronawarn/testresult/TestResultController.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
package app.coronawarn.testresult;
2323

2424
import app.coronawarn.testresult.model.QuickTestResult;
25+
import app.coronawarn.testresult.model.QuickTestResultList;
2526
import app.coronawarn.testresult.model.TestResult;
2627
import app.coronawarn.testresult.model.TestResultList;
2728
import app.coronawarn.testresult.model.TestResultRequest;
@@ -31,14 +32,15 @@
3132
import javax.validation.constraints.NotNull;
3233
import lombok.RequiredArgsConstructor;
3334
import lombok.extern.slf4j.Slf4j;
34-
import org.springframework.http.HttpStatus;
3535
import org.springframework.http.MediaType;
3636
import org.springframework.http.ResponseEntity;
3737
import org.springframework.validation.annotation.Validated;
3838
import org.springframework.web.bind.annotation.PostMapping;
3939
import org.springframework.web.bind.annotation.RequestBody;
4040
import org.springframework.web.bind.annotation.RestController;
4141

42+
43+
4244
@Slf4j
4345
@RequiredArgsConstructor
4446
@Validated
@@ -65,7 +67,30 @@ public ResponseEntity<TestResultResponse> result(
6567
@RequestBody @Valid TestResultRequest request
6668
) {
6769
log.info("Received test result request from app.");
68-
TestResult result = testResultService.getOrCreate(request.getId());
70+
TestResult result = testResultService.getOrCreate(request.getId(),false);
71+
return ResponseEntity.ok(new TestResultResponse()
72+
.setTestResult(result.getResult()));
73+
}
74+
75+
/**
76+
* Get the test result response from a request containing the id.
77+
*
78+
* @param request the test result request with id
79+
* @return the test result response
80+
*/
81+
@Operation(
82+
description = "Get test result response from request."
83+
)
84+
@PostMapping(
85+
value = "/api/v1/quicktest/result",
86+
consumes = MediaType.APPLICATION_JSON_VALUE,
87+
produces = MediaType.APPLICATION_JSON_VALUE
88+
)
89+
public ResponseEntity<TestResultResponse> quickTestResult(
90+
@RequestBody @Valid TestResultRequest request
91+
) {
92+
log.info("Received test result request from Quicktest.");
93+
TestResult result = testResultService.getOrCreate(request.getId(),true);
6994
return ResponseEntity.ok(new TestResultResponse()
7095
.setTestResult(result.getResult()));
7196
}
@@ -95,7 +120,7 @@ public ResponseEntity<?> results(
95120
/**
96121
* Insert or update the quick test.
97122
*
98-
* @param testResult the test result to update.
123+
* @param list the test result list request
99124
* @return the response
100125
*/
101126
@Operation(
@@ -107,10 +132,12 @@ public ResponseEntity<?> results(
107132
produces = MediaType.APPLICATION_JSON_VALUE
108133
)
109134
public ResponseEntity<?> quicktestResults(
110-
@RequestBody @NotNull @Valid QuickTestResult testResult
135+
@RequestBody @NotNull @Valid QuickTestResultList list
111136
) {
112-
log.info("Received test result to insert or update from Quicktests.");
113-
testResultService.createOrUpdate(testResultService.convertQuickTest(testResult));
114-
return ResponseEntity.status(HttpStatus.CREATED).build();
137+
log.info("Received {} test result to insert or update from Quicktests. ", list.getTestResults().size());
138+
for (QuickTestResult result: list.getTestResults()) {
139+
testResultService.createOrUpdate(testResultService.convertQuickTest(result));
140+
}
141+
return ResponseEntity.noContent().build();
115142
}
116143
}

src/main/java/app/coronawarn/testresult/TestResultService.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,20 @@ public TestResult createOrUpdate(final TestResult result) {
101101
* @param id the test result id
102102
* @return the test result
103103
*/
104-
public TestResult getOrCreate(final String id) {
104+
public TestResult getOrCreate(final String id, boolean quicktest) {
105105
try {
106106
TestResultEntity entity = testResultRepository.findByResultId(id)
107107
.orElseGet(() -> {
108108
log.info("Get failed now creating test result in database.");
109-
return testResultRepository.save(new TestResultEntity()
110-
.setResult(TestResultEntity.Result.PENDING.ordinal())
111-
.setResultId(id)
112-
.setResultDate(LocalDateTime.now()));
109+
TestResultEntity resultEntity = new TestResultEntity();
110+
if (quicktest) {
111+
resultEntity.setResult(TestResultEntity.Result.QUICK_PENDING.ordinal());
112+
} else {
113+
resultEntity.setResult(TestResultEntity.Result.PENDING.ordinal());
114+
}
115+
resultEntity.setResultId(id);
116+
resultEntity.setResultDate(LocalDateTime.now());
117+
return testResultRepository.save(resultEntity);
113118
});
114119
return toModel(entity);
115120
} catch (Exception e) {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Corona-Warn-App / cwa-testresult-server
3+
*
4+
* (C) 2020, T-Systems International GmbH
5+
*
6+
* Deutsche Telekom AG and all other contributors /
7+
* copyright owners license this file to you under the Apache
8+
* License, Version 2.0 (the "License"); you may not use this
9+
* file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
package app.coronawarn.testresult.model;
23+
24+
import io.swagger.v3.oas.annotations.media.Schema;
25+
import java.util.List;
26+
import javax.validation.Valid;
27+
import javax.validation.constraints.NotEmpty;
28+
import javax.validation.constraints.NotNull;
29+
import lombok.EqualsAndHashCode;
30+
import lombok.Getter;
31+
import lombok.ToString;
32+
33+
/**
34+
* Model of the test result list.
35+
*/
36+
@Schema(
37+
description = "The test result list model."
38+
)
39+
@Getter
40+
@ToString
41+
@EqualsAndHashCode
42+
public class QuickTestResultList {
43+
44+
/**
45+
* The test result entries.
46+
*/
47+
@NotNull
48+
@NotEmpty
49+
private List<@Valid QuickTestResult> testResults;
50+
51+
public QuickTestResultList setTestResults(List<QuickTestResult> testResults) {
52+
this.testResults = testResults;
53+
return this;
54+
}
55+
}

src/main/java/app/coronawarn/testresult/model/TestResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class TestResult {
6363
* 9: quick-test-Redeemed
6464
*/
6565
@Min(1)
66-
@Max(9)
66+
@Max(3)
6767
@NotNull
6868
private Integer result;
6969

src/test/java/app/coronawarn/testresult/TestResultControllerTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121

2222
package app.coronawarn.testresult;
2323

24-
import app.coronawarn.testresult.model.QuickTestResult;
25-
import app.coronawarn.testresult.model.TestResult;
26-
import app.coronawarn.testresult.model.TestResultList;
27-
import app.coronawarn.testresult.model.TestResultRequest;
24+
import app.coronawarn.testresult.model.*;
2825
import com.fasterxml.jackson.databind.ObjectMapper;
2926
import java.util.Collections;
3027
import java.util.List;
@@ -183,14 +180,17 @@ public void quickInsertValidShouldReturnNoContent() throws Exception {
183180
String id = "b".repeat(64);
184181
Integer result = 5;
185182
// create
186-
QuickTestResult valid = new QuickTestResult().setId(id).setResult(result);
183+
QuickTestResultList valid = new QuickTestResultList();
184+
valid.setTestResults( Collections.singletonList(
185+
new QuickTestResult().setId(id).setResult(result)
186+
));
187187
mockMvc.perform(MockMvcRequestBuilders
188188
.post("/api/v1/quicktest/results")
189189
.accept(MediaType.APPLICATION_JSON_VALUE)
190190
.contentType(MediaType.APPLICATION_JSON_VALUE)
191191
.content(objectMapper.writeValueAsString(valid)))
192192
.andDo(MockMvcResultHandlers.print())
193-
.andExpect(MockMvcResultMatchers.status().isCreated());
193+
.andExpect(MockMvcResultMatchers.status().isNoContent());
194194
}
195195

196196
@Test
@@ -199,7 +199,10 @@ public void quickInsertInValidShouldReturnUnprocessableEntity() throws Exception
199199
String id = "b".repeat(64);
200200
Integer result = 4;
201201
// create
202-
QuickTestResult valid = new QuickTestResult().setId(id).setResult(result);
202+
QuickTestResultList valid = new QuickTestResultList();
203+
valid.setTestResults( Collections.singletonList(
204+
new QuickTestResult().setId(id).setResult(result)
205+
));
203206
mockMvc.perform(MockMvcRequestBuilders
204207
.post("/api/v1/quicktest/results")
205208
.accept(MediaType.APPLICATION_JSON_VALUE)

src/test/java/app/coronawarn/testresult/TestResultServiceTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void insertOrUpdate() {
8282
Assert.assertNotNull(create);
8383
Assert.assertEquals(result, create.getResult());
8484
// get
85-
TestResult get = testResultService.getOrCreate(id);
85+
TestResult get = testResultService.getOrCreate(id,false);
8686
Assert.assertNotNull(get);
8787
Assert.assertEquals(result, get.getResult());
8888
}
@@ -101,7 +101,7 @@ public void insertAndUpdate() {
101101
Assert.assertNotNull(create);
102102
Assert.assertEquals(resultCreate, create.getResult());
103103
// get
104-
TestResult get = testResultService.getOrCreate(id);
104+
TestResult get = testResultService.getOrCreate(id,false);
105105
Assert.assertNotNull(get);
106106
Assert.assertEquals(resultCreate, get.getResult());
107107
// update
@@ -112,7 +112,7 @@ public void insertAndUpdate() {
112112
Assert.assertNotNull(update);
113113
Assert.assertEquals(resultUpdate, update.getResult());
114114
// get
115-
get = testResultService.getOrCreate(id);
115+
get = testResultService.getOrCreate(id,false);
116116
Assert.assertNotNull(get);
117117
Assert.assertEquals(resultUpdate, get.getResult());
118118
}
@@ -123,7 +123,7 @@ public void getOrCreate() {
123123
String id = "a".repeat(64);
124124
Integer result = 0;
125125
// get
126-
TestResult get = testResultService.getOrCreate(id);
126+
TestResult get = testResultService.getOrCreate(id,false);
127127
Assert.assertNotNull(get);
128128
Assert.assertEquals(result, get.getResult());
129129
}

0 commit comments

Comments
 (0)