Commit 7ca095ef by Patryk Czarnik

Lista produktów i jeden produkt - pierwsza wersja

parent 4fd59bcd
package sklep.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import sklep.model.Customer;
@Repository
public interface CustomerRepository extends JpaRepository<Customer, String> {
}
package sklep.repository;
import java.math.BigDecimal;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import sklep.model.Product;
@Repository
public interface ProductRepository extends JpaRepository<Product, Integer> {
List<Product> findByProductName(String name);
List<Product> findByProductNameContaining(String name);
List<Product> findByProductNameContainingIgnoringCase(String name);
List<Product> findByPriceBetween(BigDecimal min, BigDecimal max);
List<Product> findByProductNameContainingIgnoringCaseAndPriceBetween(String name, BigDecimal min, BigDecimal max);
}
package sklep.rest;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import sklep.model.Product;
import sklep.repository.ProductRepository;
@Controller
public class ProductController {
private ProductRepository productRepository;
public ProductController(ProductRepository productRepository) {
this.productRepository = productRepository;
}
@GetMapping("products")
@ResponseBody
public List<Product> readAll() {
return productRepository.findAll();
}
@GetMapping("products/{id}")
@ResponseBody
public Product readOne(@PathVariable int id) {
return productRepository.findById(id).get();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment