Skip to content

Commit 71065bb

Browse files
committed
feat(spring boot 5): add first Spring 5 / Spring Boot 2 / Webflux based implementation
1 parent a61c82b commit 71065bb

18 files changed

Lines changed: 619 additions & 2 deletions

.idea/gradle.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/spring5/spring5.iml

Lines changed: 79 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/Spring5__Run_Example.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

settings.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ include ':spark'
33
include ':ninja'
44
include ':ratpack'
55
include ':jodd'
6-
include ':pippo'
6+
include ':pippo'
7+
include ':spring5'

spring5/build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
plugins {
2+
id 'org.springframework.boot' version '2.0.0.RELEASE'
3+
}
4+
5+
dependencies {
6+
apply plugin: 'application'
7+
apply plugin: 'org.springframework.boot'
8+
apply plugin: 'io.spring.dependency-management'
9+
mainClassName = "bentolor.grocerylist.GroceryListApp"
10+
11+
compile 'org.springframework.boot:spring-boot-starter-webflux:2.0.0.RELEASE',
12+
'com.google.code.gson:gson:2.8.2',
13+
'org.projectlombok:lombok:1.16.20'
14+
15+
testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.3'
16+
17+
//runtime 'org.slf4j:slf4j-simple:1.7.25'
18+
}

spring5/grocerylists.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[ {
2+
"id" : "68798a5c-be46-41b8-985a-1b6f32fefd4c",
3+
"shoppingItems" : [ {
4+
"quantity" : 5,
5+
"unit" : "pcs",
6+
"name" : "apples"
7+
}, {
8+
"quantity" : 2,
9+
"unit" : "l",
10+
"name" : "soy milk"
11+
}, {
12+
"quantity" : 500,
13+
"unit" : "g",
14+
"name" : "vegan cheese"
15+
} ],
16+
"comment" : "Shopping List for week 32/2015",
17+
"date" : "2015-08-08",
18+
"settled" : true
19+
}, {
20+
"id" : "5e9d65d7-8377-4013-a73f-7389fdcb8bcd",
21+
"shoppingItems" : [ {
22+
"quantity" : 1,
23+
"unit" : "pcs",
24+
"name" : "Canyon mountain bike"
25+
}, {
26+
"quantity" : 3,
27+
"unit" : "pcs",
28+
"name" : "socks"
29+
} ],
30+
"comment" : "Wishlist for christmas",
31+
"date" : "2015-12-22",
32+
"settled" : false
33+
}, {
34+
"id" : "723a1872-9806-40d6-8540-cedd95209fbd",
35+
"shoppingItems" : null,
36+
"comment" : "Shopping List for week 33/2015",
37+
"date" : "2015-08-15",
38+
"settled" : false
39+
} ]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package bentolor.grocerylist;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class GroceryListApp {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(GroceryListApp.class, args);
11+
}
12+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2015 Benjamin Schmid, @bentolor
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package bentolor.grocerylist;
17+
18+
import bentolor.grocerylist.model.GroceryList;
19+
import bentolor.grocerylist.persistence.ReactiveRepository;
20+
import lombok.RequiredArgsConstructor;
21+
import org.springframework.http.MediaType;
22+
import org.springframework.web.bind.annotation.*;
23+
import reactor.core.publisher.Flux;
24+
import reactor.core.publisher.Mono;
25+
26+
import java.util.UUID;
27+
28+
/**
29+
* @author Benjamin Schmid <benjamin.schmid@exxcellent.de>
30+
*/
31+
@RestController
32+
@RequiredArgsConstructor
33+
public class GroceryListController {
34+
35+
private final ReactiveRepository repository;
36+
37+
@GetMapping(path = "/lists",
38+
produces = { MediaType.APPLICATION_JSON_VALUE })
39+
Flux<GroceryList> listStream() {
40+
return repository.getLists();
41+
}
42+
43+
@GetMapping("/list/{id}")
44+
public Mono<GroceryList> getList(@PathVariable(value = "id") UUID id) {
45+
return repository.getList(id);
46+
}
47+
48+
@PostMapping("/list")
49+
public Mono<UUID> createList(GroceryList newList) {
50+
return repository.createList(newList);
51+
}
52+
53+
@PutMapping("/list/{id}")
54+
public Mono<GroceryList> createList(@PathVariable(value = "id") UUID id, GroceryList updatedList) {
55+
return repository.updateList(id, updatedList);
56+
}
57+
58+
@DeleteMapping("/list/{id}")
59+
public Mono<UUID> deleteList(@PathVariable(value = "id") UUID id) {
60+
return repository.deleteList(id);
61+
}
62+
63+
64+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2015 Benjamin Schmid, @bentolor
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package bentolor.grocerylist.model;
17+
18+
import lombok.Data;
19+
20+
import java.time.LocalDate;
21+
import java.util.Arrays;
22+
import java.util.List;
23+
import java.util.UUID;
24+
25+
/** A shopping list for groceries. */
26+
@Data
27+
public class GroceryList implements ModelElement {
28+
29+
private UUID id;
30+
private List<Item> shoppingItems;
31+
private String comment;
32+
private LocalDate date;
33+
private boolean settled;
34+
35+
public GroceryList() {
36+
}
37+
38+
public GroceryList(UUID id, LocalDate date, String comment, boolean settled, Item... shoppingItems) {
39+
this.id = id;
40+
this.shoppingItems = Arrays.asList(shoppingItems);
41+
this.comment = comment;
42+
this.date = date;
43+
this.settled = settled;
44+
}
45+
46+
}

0 commit comments

Comments
 (0)