Skip to content

Commit fbc886a

Browse files
Service Refactoring
1 parent 8b016ec commit fbc886a

32 files changed

+1116
-748
lines changed

src/main/java/org/woehlke/greenshop/CheckoutController.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.springframework.web.bind.annotation.RequestMapping;
1313
import org.springframework.web.bind.annotation.RequestMethod;
1414
import org.springframework.web.bind.annotation.SessionAttributes;
15+
import org.woehlke.greenshop.customer.service.CountryService;
1516
import org.woehlke.greenshop.cart.model.TransientBasket;
1617
import org.woehlke.greenshop.checkout.CheckoutService;
1718
import org.woehlke.greenshop.checkout.model.AddressBean;
@@ -26,6 +27,9 @@ public class CheckoutController extends AbstractController {
2627

2728
@Inject
2829
private CheckoutService checkoutService;
30+
31+
@Inject
32+
private CountryService countryService;
2933

3034
@ModelAttribute("checkout")
3135
public CheckoutBean createCheckoutBean(){
@@ -107,7 +111,7 @@ public String checkoutShippingAddress(
107111
AddressBean newAddress = new AddressBean();
108112
newAddress.setChoosenAddressId(customer.getDefaultAddress().getId());
109113
model.addAttribute("newAddress", newAddress);
110-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
114+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
111115
model.addAttribute("allCountriesOrderByName", allCountriesOrderByName);
112116
return "checkoutShippingAddress";
113117
}
@@ -131,11 +135,11 @@ public String checkoutShippingAddress(
131135
if(result.hasErrors()){
132136
List<AddressBook> addressBook = super.customerService.findAddressBookForCustomer(customer);
133137
model.addAttribute("addressBook", addressBook);
134-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
138+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
135139
model.addAttribute("allCountriesOrderByName",allCountriesOrderByName);
136140
return "checkoutShippingAddress";
137141
} else {
138-
Country country = super.customerService.findCountryById(newAddress.getCountryId());
142+
Country country = countryService.findCountryById(newAddress.getCountryId());
139143
newAddress.setCountryName(country.getName());
140144
AddressBook a = checkoutService.transformBeanToPersistentAddress(newAddress,country,customer);
141145
super.customerService.addAddress(a);
@@ -159,7 +163,7 @@ public String checkoutPaymentAddress(
159163
AddressBean newAddress = new AddressBean();
160164
newAddress.setChoosenAddressId(customer.getDefaultAddress().getId());
161165
model.addAttribute("newAddress", newAddress);
162-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
166+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
163167
model.addAttribute("allCountriesOrderByName", allCountriesOrderByName);
164168
return "checkoutPaymentAddress";
165169
}
@@ -183,11 +187,11 @@ public String checkoutPaymentAddress(
183187
if(result.hasErrors()){
184188
List<AddressBook> addressBook = super.customerService.findAddressBookForCustomer(customer);
185189
model.addAttribute("addressBook", addressBook);
186-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
190+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
187191
model.addAttribute("allCountriesOrderByName",allCountriesOrderByName);
188192
return "checkoutShippingAddress";
189193
} else {
190-
Country country = super.customerService.findCountryById(newAddress.getCountryId());
194+
Country country = countryService.findCountryById(newAddress.getCountryId());
191195
newAddress.setCountryName(country.getName());
192196
AddressBook a = checkoutService.transformBeanToPersistentAddress(newAddress, country, customer);
193197
super.customerService.addAddress(a);

src/main/java/org/woehlke/greenshop/CreateAccountController.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.springframework.web.bind.annotation.RequestMapping;
2020
import org.springframework.web.bind.annotation.RequestMethod;
2121
import org.springframework.web.bind.annotation.SessionAttributes;
22+
import org.woehlke.greenshop.customer.service.CountryService;
2223
import org.woehlke.greenshop.customer.CustomerService;
2324
import org.woehlke.greenshop.customer.entities.Country;
2425
import org.woehlke.greenshop.customer.model.CreateNewCustomerFormBean;
@@ -31,13 +32,16 @@ public class CreateAccountController extends AbstractController {
3132

3233
@Inject
3334
private CustomerService customerService;
35+
36+
@Inject
37+
private CountryService countryService;
3438

3539
@RequestMapping(value = "/createAccount", method = RequestMethod.GET)
3640
public String createNewCustomerForm(Model model){
3741
super.getDefaultBoxContent(model);
3842
CreateNewCustomerFormBean createNewCustomerFormBean = new CreateNewCustomerFormBean();
3943
model.addAttribute("createNewCustomerFormBean",createNewCustomerFormBean);
40-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
44+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
4145
model.addAttribute("allCountriesOrderByName",allCountriesOrderByName);
4246
return "createAccount";
4347
}
@@ -55,7 +59,7 @@ public String createNewCustomer(
5559
result.addError(new FieldError("createNewCustomerFormBean","confirmation","passwords doesn't match"));
5660
}
5761
if(result.hasErrors()){
58-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
62+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
5963
model.addAttribute("allCountriesOrderByName",allCountriesOrderByName);
6064
for(ObjectError e :result.getAllErrors()){
6165
logger.info(e.toString());

src/main/java/org/woehlke/greenshop/UserController.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.springframework.validation.FieldError;
1919
import org.springframework.web.bind.WebDataBinder;
2020
import org.springframework.web.bind.annotation.*;
21+
import org.woehlke.greenshop.customer.service.CountryService;
2122
import org.woehlke.greenshop.catalog.entities.Language;
2223
import org.woehlke.greenshop.catalog.entities.ProductDescription;
2324
import org.woehlke.greenshop.checkout.OrderService;
@@ -41,6 +42,8 @@ public class UserController extends AbstractController {
4142
@Inject
4243
private OrderService orderService;
4344

45+
@Inject
46+
private CountryService countryService;
4447

4548
@InitBinder
4649
public void initBinder(WebDataBinder binder) {
@@ -111,7 +114,7 @@ public String addressBookEditForm(@PathVariable long addressId, Model model){
111114
Customer customer = customerService.findCustomerByEmail(customerEmail);
112115
model.addAttribute("customer",customer);
113116
AddressBook customersAddress = customerService.findAddressById(addressId);
114-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
117+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
115118
model.addAttribute("allCountriesOrderByName",allCountriesOrderByName);
116119
CustomerAddressBean addressBean = new CustomerAddressBean();
117120
addressBean.setGender(customersAddress.getGender());
@@ -138,12 +141,12 @@ public String addressBookEditStore(
138141
model.addAttribute("customer",customer);
139142
if (result.hasErrors()){
140143
super.getDefaultBoxContent(model);
141-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
144+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
142145
model.addAttribute("allCountriesOrderByName",allCountriesOrderByName);
143146
return "addressBookEdit";
144147
} else {
145148
AddressBook persistentAddress = customerService.findAddressById(addressId);
146-
Country country = customerService.findCountryById(customersAddress.getCountry());
149+
Country country = countryService.findCountryById(customersAddress.getCountry());
147150
persistentAddress.setCity(customersAddress.getCity());
148151
persistentAddress.setCompany(customersAddress.getCompany());
149152
persistentAddress.setCountry(country);
@@ -167,7 +170,7 @@ public String addressBookAddForm(Model model){
167170
String customerEmail = auth.getName();
168171
Customer customer = customerService.findCustomerByEmail(customerEmail);
169172
model.addAttribute("customer",customer);
170-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
173+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
171174
model.addAttribute("allCountriesOrderByName",allCountriesOrderByName);
172175
CustomerAddressBean addressBean = new CustomerAddressBean();
173176
model.addAttribute("customersAddress",addressBean);
@@ -182,13 +185,13 @@ public String addressBookAddPerform(@Valid CustomerAddressBean customersAddress,
182185
model.addAttribute("customer",customer);
183186
if(result.hasErrors()){
184187
super.getDefaultBoxContent(model);
185-
List<Country> allCountriesOrderByName = customerService.findAllCountriesOrderByName();
188+
List<Country> allCountriesOrderByName = countryService.findAllCountriesOrderByName();
186189
model.addAttribute("allCountriesOrderByName",allCountriesOrderByName);
187190
model.addAttribute("customersAddress",customersAddress);
188191
return "addressBookAdd";
189192
} else {
190193
AddressBook persistentAddress = new AddressBook();
191-
Country country = customerService.findCountryById(customersAddress.getCountry());
194+
Country country = countryService.findCountryById(customersAddress.getCountry());
192195
persistentAddress.setCustomer(customer);
193196
persistentAddress.setCity(customersAddress.getCity());
194197
persistentAddress.setCompany(customersAddress.getCompany());

0 commit comments

Comments
 (0)