Skip to content

Instantly share code, notes, and snippets.

@bion
Last active February 23, 2021 21:26
Show Gist options
  • Save bion/ec9d9f663aeb6b46d95c70ee2a86d158 to your computer and use it in GitHub Desktop.
Save bion/ec9d9f663aeb6b46d95c70ee2a86d158 to your computer and use it in GitHub Desktop.
applicant system controller sketches
class ApplicantProgramBlocksController {
// GET /applicants/22/programs/12/block/21/edit
public CompletionStage<Response> edit(long applicantId, long programId, long blockId) {
return applicantService.getReadOnlyApplicantService(applicantId, programId)
.then((ReadOnlyApplicantService roApplicantService) -> {
ImmutableList<Block> blockList = roApplicantService.getCurrentBlockList();
return ok(views.html.blockForm.render(blockList, blockId));
});
}
// PATCH or PUT /applicants/22/programs/12/block/21
public CompletionStage<Response> update(long applicantId, long programId, long blockId, Form formData) {
ImmutableList<Update> updates = getUpdates(formData);
return applicantService
.update(applicantId, updates, programId)
.then((ErrorAnd<ReadOnlyApplicantService> errorAnd) -> {
ReadOnlyApplicantService roApplicantService = errorAnd.getWrapped();
if (errorAnd.isError()) {
ImmutableList<Block> blockList = roApplicantService.getCurrentBlockList();
return badRequest(views.html.blockForm.render(
blockList,
blockId,
updates,
errorAnd.getErrors()));
} else {
Block nextBlock = roApplicantService.getBlockAfter(blockId);
return redirect(controllers.routes.ApplicantProgramBlocksController.edit(programId, nextBlock.id()));
}
});
}
}
class ApplicantProgramsController {
public CompletionStage<Response> index(long applicantId) {
return programService.getAllThePrograms().then(programList -> {
return ok(controllers.ApplicantProgramsController.index(programList));
});
}
// GET /applicants/22/programs/12/edit
public CompletionStage<Response> edit(long applicantId, long programId) {
return applicantService.getReadOnlyApplicantService(applicantId, programId)
.then((ReadOnlyApplicantService roApplicantService) -> {
Block firstBlock = roApplicantService.getFirstIncompleteBlock();
return redirect(controllers.routes.ApplicantProgramBlocksController.edit(programId, firstBlock));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment