Skip to content

Instantly share code, notes, and snippets.

@jmsalcido
Last active February 9, 2016 06:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmsalcido/f4bea37155e7ba94fb96 to your computer and use it in GitHub Desktop.
Save jmsalcido/f4bea37155e7ba94fb96 to your computer and use it in GitHub Desktop.
Stupid Controllers
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