Skip to content

Commit 3759285

Browse files
committed
zero-downtime example
1 parent 2e74db8 commit 3759285

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

spring-boot/zero-downtime/src/main/java/io/reflectoring/zerodowntime/CustomerController.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package io.reflectoring.zerodowntime;
22

33
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.PathVariable;
45
import org.springframework.web.bind.annotation.RestController;
56

7+
import java.util.Optional;
8+
69
@RestController
710
public class CustomerController {
811

@@ -17,7 +20,7 @@ public CustomerController(CustomerRepository oldCustomerRepository, NewCustomerR
1720
}
1821

1922
@GetMapping("/customers/create")
20-
String createUser() {
23+
String createCustomer() {
2124
if (featureFlagService.writeToNewCustomerSchema()) {
2225
NewCustomer customer = new NewCustomer("Bob", "Builder", "Build Street", "21");
2326
newCustomerRepository.save(customer);
@@ -28,8 +31,19 @@ String createUser() {
2831
return "customer created";
2932
}
3033

34+
@GetMapping("/customers/{id}}")
35+
String getCustomer(@PathVariable("id") Long id) {
36+
if (featureFlagService.readFromNewCustomerSchema()) {
37+
Optional<NewCustomer> customer = newCustomerRepository.findById(id);
38+
return customer.get().toString();
39+
} else {
40+
Optional<OldCustomer> customer = oldCustomerRepository.findById(id);
41+
return customer.get().toString();
42+
}
43+
}
44+
3145
@GetMapping("/customers/list")
32-
String showUser() {
46+
String getCustomer() {
3347
StringBuffer buffer = new StringBuffer();
3448
if (featureFlagService.readFromNewCustomerSchema()) {
3549
Iterable<NewCustomer> customers = newCustomerRepository.findAll();

0 commit comments

Comments
 (0)