package app.controllers; import java.util.List; import app.models.<%= class_name %>; import app.repositories.<%= repository_class_name %>; import br.com.caelum.vraptor.Delete; import br.com.caelum.vraptor.Get; import br.com.caelum.vraptor.Path; 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_class_name %> repository; private final Validator validator; public <%= controller_class_name %>(Result result, <%= repository_class_name %> repository, Validator validator) { this.result = result; this.repository = repository; this.validator = validator; } @Get @Path("<%= path %>") public List<<%= class_name %>> index() { return repository.findAll(); } @Post @Path("<%= path %>") public void create(<%= class_name %> <%= @model %>) { validator.validate(<%= @model %>); validator.onErrorUsePageOf(this).new<%= class_name %>(); repository.create(<%= @model %>); result.redirectTo(this).index(); } @Get @Path("<%= "#{path}/new" %>") public <%= class_name %> new<%= class_name %>() { return new <%= class_name %>(); } @Put @Path("<%= path %>") public void update(<%= class_name %> <%= @model %>) { validator.validate(<%= @model %>); validator.onErrorUsePageOf(this).edit(<%= @model %>); repository.update(<%= @model %>); result.redirectTo(this).index(); } @Get @Path("<%= "#{path}/{#{@model}.id}/edit" %>") public <%= class_name %> edit(<%= class_name %> <%= @model %>) { return repository.find(<%= @model %>.getId()); } @Get @Path("<%= "#{path}/{#{@model}.id}/show" %>") public <%= class_name %> show(<%= class_name %> <%= @model %>) { return repository.find(<%= @model %>.getId()); } @Delete @Path("<%= path %>") public void destroy(<%= class_name %> <%= @model %>) { repository.destroy(repository.find(<%= @model %>.getId())); result.redirectTo(this).index(); } }