#319 Refactoring an Action Processing Controller
Perform a refactoring:
@RestController
@Transactional
@RequiredArgsConstructor
public class ProcessActionController {
private final PushHandler pushHandler;
private final SmsHandler smsHandler;
@PostMapping(value = "/doAction", consumes = {MediaType.ALL_VALUE})
public ResponseEntity<Object> doIt(@ResponseBody @Valid ActionRequ request) {
Action a = request.getaction();
if (a == Action.SEND_PUSH)) {
return pushHandler.process(request);
}
if (a == Action.SEND_SMS) {
return smsHandler.process(request);
}
return ResponseEntity.ok().body(UserRs.getDefaultResponce("It's default response. "));
}
}
@Data
class ActionRequ {
@NotNull
private Integer id;
@NotNull
private Action action;
//...
}
Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor