package <%= Configuration.package %>.<%= Configuration.controllers_package %>; import java.util.List; import <%= Configuration.full_models_package %>.<%= class_name %>; import <%= Configuration.package %>.<%= Configuration.repositories_package %>.<%= repository_interface_name %>; import br.com.caelum.vraptor.Delete; import br.com.caelum.vraptor.Get; import br.com.caelum.vraptor.Post; import br.com.caelum.vraptor.Put; import br.com.caelum.vraptor.Resource; import br.com.caelum.vraptor.Result; import br.com.caelum.vraptor.Validator; @Resource public class <%= controller_class_name %> { private final Result result; private final <%= repository_interface_name %> repository; private final Validator validator; <%= controller_class_name %>(Result result, <%= repository_interface_name %> repository, Validator validator) { this.result = result; this.repository = repository; this.validator = validator; } @Get("<%= path %>") public List<<%= class_name %>> index() { return repository.findAll(); } @Post("<%= path %>") public void create(<%= class_name %> <%= model_parameter_name %>) { validator.validate(<%= model_parameter_name %>); validator.onErrorUsePageOf(this).new<%= class_name %>(); repository.create(<%= model_parameter_name %>); result.redirectTo(this).index(); } @Get("<%= "#{path}/new" %>") public <%= class_name %> new<%= class_name %>() { return new <%= class_name %>(); } @Put("<%= path %>") public void update(<%= class_name %> <%= model_parameter_name %>) { validator.validate(<%= model_parameter_name %>); validator.onErrorUsePageOf(this).edit(<%= model_parameter_name %>); repository.update(<%= model_parameter_name %>); result.redirectTo(this).index(); } @Get("<%= "#{path}/{#{model_parameter_name}.id}/edit" %>") public <%= class_name %> edit(<%= class_name %> <%= model_parameter_name %>) { return repository.find(<%= model_parameter_name %>.getId()); } @Get("<%= "#{path}/{#{model_parameter_name}.id}" %>") public <%= class_name %> show(<%= class_name %> <%= model_parameter_name %>) { return repository.find(<%= model_parameter_name %>.getId()); } @Delete("<%= "#{path}/{#{model_parameter_name}.id}" %>") public void destroy(<%= class_name %> <%= model_parameter_name %>) { repository.destroy(repository.find(<%= model_parameter_name %>.getId())); result.redirectTo(this).index(); } }