package sklep.rest;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import sklep.model.Product;
import sklep.repository.ProductRepository;

@RestController
@RequestMapping("/products")
public class ProductController {
	private ProductRepository productRepository;

	public ProductController(ProductRepository productRepository) {
		this.productRepository = productRepository;
	}

	@GetMapping
	public List<Product> readAll() {
		return productRepository.findAll();
	}
	
	@GetMapping("/{id}")
	public Product readOne(@PathVariable int id) {
		return productRepository.findById(id).get();
	}
}
