11package io .reflectoring .zerodowntime ;
22
33import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .PathVariable ;
45import org .springframework .web .bind .annotation .RestController ;
56
7+ import java .util .Optional ;
8+
69@ RestController
710public 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