#319 Refactoring an Action Processing Controller

Companies:
Sberbank
Themes:
SpringSpring BootPractice

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

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in