Sha256: 949ac0de31a3b131e61818bbe24946db561353bcf082e3fe5caa84eb2389e5b8

Contents?: true

Size: 1.76 KB

Versions: 2

Compression:

Stored size: 1.76 KB

Contents

package app.controllers;

import java.util.List;

import app.models.Product;
import app.repositories.ProductRepository;
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 ProductController {

	private final Result result;
	private final ProductRepository repository;
	private final Validator validator;
	
	public ProductController(Result result, ProductRepository repository, Validator validator) {
		this.result = result;
		this.repository = repository;
		this.validator = validator;
	}
	
	@Get
	@Path("/products")
	public List<Product> index() {
		return repository.findAll();
	}
	
	@Post
	@Path("/products")
	public void create(Product product) {
		validator.validate(product);
		validator.onErrorUsePageOf(this).newProduct();
		repository.create(product);
		result.redirectTo(this).index();
	}
	
	@Get
	@Path("/products/new")
	public Product newProduct() {
		return new Product();
	}
	
	@Put
	@Path("/products")
	public void update(Product product) {
		validator.validate(product);
		validator.onErrorUsePageOf(this).edit(product);
		repository.update(product);
		result.redirectTo(this).index();
	}
	
	@Get
	@Path("/products/{product.id}/edit")
	public Product edit(Product product) {
		return repository.find(product.getId());
	}

	@Get
	@Path("/products/{product.id}/show")
	public Product show(Product product) {
		return repository.find(product.getId());
	}

	@Delete
	@Path("/products")
	public void destroy(Product product) {
		repository.destroy(repository.find(product.getId()));
		result.redirectTo(this).index();  
	}
	
}

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vraptor-scaffold-0.0.1.rc spec/lib/generators/scaffold_generator/controller_generator/templates/ProductController.java
vraptor-scaffold-0.0.1.beta5 spec/lib/generators/scaffold_generator/controller_generator/templates/ProductController.java