Skip to content

Commit

Permalink
Decouple presenter logic on GetAllWorkersController
Browse files Browse the repository at this point in the history
  • Loading branch information
palpa committed Mar 12, 2015
1 parent fa5909d commit 7becc39
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,36 @@

@Controller
@RequestMapping(value = "/workers", produces = "application/hal+json")
public final class GetAllWorkersController implements GetAllWorkersResponder {
public final class GetAllWorkersController {
private final UseCaseActivator interactor;
private final GetAllWorkersRequestBuilder requestBuilder;

private Iterable<WorkerDTO> workerList = Collections.emptyList();

@Autowired
public GetAllWorkersController(@Qualifier("GetAllWorkersInteractor") UseCaseActivator interactor,
GetAllWorkersRequestBuilder requestBuilder) {
this.interactor = interactor;
this.requestBuilder = requestBuilder;
}

@RequestMapping(method = RequestMethod.GET) ResponseEntity<Resources<WorkerDTO>> getWorkers() {
UseCaseRequest request = requestBuilder.buildGetAllWorkersRequest(this);
@RequestMapping(method = RequestMethod.GET) ResponseEntity<?> getWorkers() {
GetAllWorkersResponder presenter = new ResponsePresenter();
UseCaseRequest request = requestBuilder.buildGetAllWorkersRequest(presenter);

interactor.execute(request);
Resources<WorkerDTO> res = new Resources<>(this.workerList);
return new ResponseEntity<>(res, HttpStatus.OK);

return ((ResponsePresenter) presenter).getResponse();
}

@Override
public void bindModel(Collection<WorkerDTO> workerList) {
this.workerList = workerList;
private class ResponsePresenter implements GetAllWorkersResponder {
private Collection<WorkerDTO> workerList = Collections.emptyList();

@Override public void bindModel(Collection<WorkerDTO> workerList) {
this.workerList = workerList;
}

public ResponseEntity<?> getResponse() {
Resources<WorkerDTO> res = new Resources<>(this.workerList);
return new ResponseEntity<>(res, HttpStatus.OK);
}
}
}

0 comments on commit 7becc39

Please sign in to comment.