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

Commit

Permalink
feat: api (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhagestedt authored Jun 8, 2020
1 parent faad35c commit e4a04e6
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 14 deletions.
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<goals>
<goal>repackage</goal>
Expand All @@ -206,6 +218,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
package app.coronawarn.testresult;

import app.coronawarn.testresult.model.TestResult;
import app.coronawarn.testresult.model.TestResultList;
import app.coronawarn.testresult.model.TestResultRequest;
import app.coronawarn.testresult.model.TestResultResponse;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -71,7 +71,7 @@ public ResponseEntity<TestResultResponse> result(
/**
* Insert or update the test results.
*
* @param request the test result collection request
* @param list the test result list request
* @return the response
*/
@Operation(
Expand All @@ -83,10 +83,10 @@ public ResponseEntity<TestResultResponse> result(
produces = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<?> results(
@RequestBody @NotEmpty List<@Valid TestResult> request
@RequestBody @NotNull @Valid TestResultList list
) {
log.info("Received {} test results to insert or update from lab.", request.size());
request.forEach(testResultService::createOrUpdate);
log.info("Received {} test results to insert or update from lab.", list.getTestResults().size());
list.getTestResults().forEach(testResultService::createOrUpdate);
return ResponseEntity.noContent().build();
}
}
55 changes: 55 additions & 0 deletions src/main/java/app/coronawarn/testresult/model/TestResultList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Corona-Warn-App / cwa-testresult-server
*
* (C) 2020, T-Systems International GmbH
*
* Deutsche Telekom AG and all other contributors /
* copyright owners license this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package app.coronawarn.testresult.model;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

/**
* Model of the test result list.
*/
@Schema(
description = "The test result list model."
)
@Getter
@ToString
@EqualsAndHashCode
public class TestResultList {

/**
* The test result entries.
*/
@NotNull
@NotEmpty
private List<@Valid TestResult> testResults;

public TestResultList setTestResults(List<TestResult> testResults) {
this.testResults = testResults;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package app.coronawarn.testresult;

import app.coronawarn.testresult.model.TestResult;
import app.coronawarn.testresult.model.TestResultList;
import app.coronawarn.testresult.model.TestResultRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Collections;
Expand Down Expand Up @@ -81,9 +82,9 @@ public void insertInvalidResultShouldReturnBadRequest() throws Exception {
// data
String id = "a".repeat(64);
// create
List<TestResult> invalid = Collections.singletonList(
TestResultList invalid = new TestResultList().setTestResults(Collections.singletonList(
new TestResult().setId(id)
);
));
mockMvc.perform(MockMvcRequestBuilders
.post("/api/v1/lab/results")
.accept(MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -92,9 +93,9 @@ public void insertInvalidResultShouldReturnBadRequest() throws Exception {
.andDo(MockMvcResultHandlers.print())
.andExpect(MockMvcResultMatchers.status().isBadRequest());
// create
invalid = Collections.singletonList(
invalid = new TestResultList().setTestResults(Collections.singletonList(
new TestResult().setId(id).setResult(4)
);
));
mockMvc.perform(MockMvcRequestBuilders
.post("/api/v1/lab/results")
.accept(MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -110,9 +111,9 @@ public void insertValidShouldReturnNoContent() throws Exception {
String id = "b".repeat(64);
Integer result = 1;
// create
List<TestResult> valid = Collections.singletonList(
TestResultList valid = new TestResultList().setTestResults(Collections.singletonList(
new TestResult().setId(id).setResult(result)
);
));
mockMvc.perform(MockMvcRequestBuilders
.post("/api/v1/lab/results")
.accept(MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -128,9 +129,9 @@ public void insertValidAndGetShouldReturnOk() throws Exception {
String id = "c".repeat(64);
Integer result = 1;
// create
List<TestResult> valid = Collections.singletonList(
TestResultList valid = new TestResultList().setTestResults(Collections.singletonList(
new TestResult().setId(id).setResult(result)
);
));
mockMvc.perform(MockMvcRequestBuilders
.post("/api/v1/lab/results")
.accept(MediaType.APPLICATION_JSON_VALUE)
Expand Down

0 comments on commit e4a04e6

Please sign in to comment.