Last active
February 9, 2016 06:16
-
-
Save jmsalcido/f4bea37155e7ba94fb96 to your computer and use it in GitHub Desktop.
Stupid Controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SomeController { | |
// pretend all dependencies are here. | |
@RequestMapping(value = "/some-request", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) | |
public ResponseEntity<Response<SomeRequest> > getSomeRequest(HttpSession session) { | |
SomeRequest someRequest = this.someBusinessService.createSomeRequest(session.getId()); | |
for (String x: someRequest.getSome()) { | |
if (x.equals("someStringNotAsAConstant")) { | |
process(x); | |
} | |
} | |
User user = getUser(); | |
if (this.configurationService.getConfigurations().getBoolean("is_a_config_turned_on")) { | |
try { | |
someRequest.setSomeName(user.getName()); | |
someRequest.setSomeAddress(new Address()); | |
for (String line : user.getAddress().getAddressLines()) { | |
someRequest.getSomeAddress().addAddressLine(line); | |
} | |
someRequest.setCreditCard(user.getCreditCard()); | |
this.userService.save(someRequest); | |
} catch (Exception e) { | |
return this.data(someRequest, HttpStatus.BAD_REQUEST); | |
} | |
} | |
DifferentPaymentMethod diff = new DifferentPaymentMethod() | |
diff.setDifferentPaymentMethodName("Other Name"); | |
diff.setActivated(true); | |
someRequest.getPaymentMethod().setOtherPaymentMethod(diff); | |
return data(someRequest); | |
} | |
User getUser() { | |
return this.userService.getUser(); | |
} | |
void process(String someX) { | |
// do something with someX | |
// we use methods instead of adding logic on the controller method right? | |
this.userService.processSomeEx(someX); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment