commit 2783bfbe6da317a3123e45327a2700d381a3ab4a
parent 6626e82d1106f72e98e0dabbff2a31fd1c5eab6e
Author: Wim Dupont <wim@wimdupont.com>
Date: Sat, 18 Mar 2023 22:45:19 +0100
version bump and minor updates
Diffstat:
5 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/pom.xml b/pom.xml
@@ -10,11 +10,11 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
- <version>3.0.2</version>
+ <version>3.0.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
- <springdoc-openapi.version>2.0.2</springdoc-openapi.version>
+ <springdoc-openapi.version>2.0.4</springdoc-openapi.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
diff --git a/src/main/java/com/wimdupont/swagger/blueprint/controller/BlueprintController.java b/src/main/java/com/wimdupont/swagger/blueprint/controller/BlueprintController.java
@@ -31,6 +31,12 @@ public class BlueprintController {
return blueprintService.getBlueprints();
}
+ @GetMapping("/{id}")
+ @Operation(summary = "Retrieve blueprint", description = "This will retrieve the existing blueprint")
+ public BlueprintDto getBlueprint(@PathVariable UUID id) {
+ return blueprintService.getBlueprint(id);
+ }
+
@PostMapping
@Operation(summary = "Create blueprint", description = "This will create a new blueprint")
public BlueprintDto createBlueprint(@RequestBody BlueprintDto blueprintDto) {
@@ -38,11 +44,13 @@ public class BlueprintController {
}
@PutMapping("/{id}")
+ @Operation(summary = "Update blueprint", description = "This will update the existing blueprint")
public BlueprintDto updateBlueprint(@PathVariable UUID id, @RequestBody BlueprintDto blueprintDto) {
return blueprintService.updateBlueprint(id, blueprintDto);
}
@DeleteMapping("/{id}")
+ @Operation(summary = "Delete blueprint", description = "This will delete the existing blueprint")
public void deleteBlueprint(@PathVariable UUID id) {
blueprintService.deleteBlueprint(id);
}
diff --git a/src/main/java/com/wimdupont/swagger/blueprint/controller/dto/BlueprintDto.java b/src/main/java/com/wimdupont/swagger/blueprint/controller/dto/BlueprintDto.java
@@ -11,6 +11,7 @@ import java.util.UUID;
@JsonDeserialize(builder = BlueprintDto.Builder.class)
public class BlueprintDto {
+
@NotNull
@Schema(accessMode = AccessMode.READ_ONLY, description = "Unique identifier of the blueprint", example = "030e5b9d-b4ed-4900-af24-cb2eac570056")
UUID id;
diff --git a/src/main/java/com/wimdupont/swagger/blueprint/service/BlueprintService.java b/src/main/java/com/wimdupont/swagger/blueprint/service/BlueprintService.java
@@ -14,14 +14,29 @@ public class BlueprintService {
private final Set<BlueprintDto> blueprintDtoSet = new HashSet<>();
public BlueprintService() {
- blueprintDtoSet.add(BlueprintDto.Builder.newBuilder().id(UUID.randomUUID()).name("blueprint-one").number(420).build());
- blueprintDtoSet.add(BlueprintDto.Builder.newBuilder().id(UUID.randomUUID()).name("blueprint-two").number(666).build());
+ blueprintDtoSet.add(BlueprintDto.Builder.newBuilder()
+ .id(UUID.randomUUID())
+ .name("blueprint-one")
+ .number(420)
+ .build());
+ blueprintDtoSet.add(BlueprintDto.Builder.newBuilder()
+ .id(UUID.randomUUID())
+ .name("blueprint-two")
+ .number(666)
+ .build());
}
public Set<BlueprintDto> getBlueprints() {
return blueprintDtoSet;
}
+ public BlueprintDto getBlueprint(UUID id) {
+ return getBlueprints().stream()
+ .filter(f -> f.getId().equals(id))
+ .findAny()
+ .orElseThrow(() -> new EntityNotFoundException(BlueprintDto.class, id.toString()));
+ }
+
public BlueprintDto createBlueprint(BlueprintDto blueprintDto) {
blueprintDto.setId(UUID.randomUUID());
blueprintDtoSet.add(blueprintDto);
@@ -29,15 +44,13 @@ public class BlueprintService {
}
public BlueprintDto updateBlueprint(UUID id, BlueprintDto blueprintDto) {
- var old = getBlueprints().stream().filter(f -> f.getId().equals(id)).findAny()
- .orElseThrow(() -> new EntityNotFoundException(BlueprintDto.class, id.toString()));
- old.setName(blueprintDto.getName());
- old.setNumber(blueprintDto.getNumber());
- return old;
+ var existing = getBlueprint(id);
+ existing.setName(blueprintDto.getName());
+ existing.setNumber(blueprintDto.getNumber());
+ return existing;
}
public void deleteBlueprint(UUID id) {
- getBlueprints().remove(getBlueprints().stream().filter(f -> f.getId().equals(id)).findAny()
- .orElseThrow(() -> new EntityNotFoundException(BlueprintDto.class, id.toString())));
+ getBlueprints().remove(getBlueprint(id));
}
}
diff --git a/src/test/resources/play.sh b/src/test/resources/play.sh
@@ -19,8 +19,14 @@ get_id () {
case ${method^^} in
GET)
- curl -X GET -sw '%{http_code}' "${base_url}" | jq
- ;;
+ echo "Leave id empty to retrieve all."
+ get_id
+ if [ -z "${id}" ]; then
+ curl -X GET -sw '%{http_code}' "${base_url}" | jq
+ else
+ curl -X GET -sw '%{http_code}' "${base_url}/${id}" | jq
+ fi
+ ;;
POST)
curl -X POST -sw '%{http_code}' "${base_url}" -H 'Content-Type: application/json' -d '{"name":"Created John","number":120}' | jq