Commit 5227d823 by Patryk Czarnik

Wspólny adres /products na poziimie klasy i inne poprawki

parent 6321149f
......@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttribute;
......@@ -24,6 +25,7 @@ import sklep.repository.ProductRepository;
import sklep.utils.ExceptionUtils;
@Controller
@RequestMapping("/products")
public class ProductController {
@Autowired
private ProductRepository productRepository;
......@@ -31,7 +33,7 @@ public class ProductController {
@Autowired
private PhotoUtil photoUtil;
@GetMapping("/products")
@GetMapping
public String readAllProducts(Model model) {
List<Product> products = productRepository.findAll(Sort.by("productId"));
model.addAttribute("products", products);
......@@ -39,7 +41,7 @@ public class ProductController {
return "products";
}
@GetMapping("/products/{id}")
@GetMapping("/{id}")
public String readOneProduct(Model model, @PathVariable("id") int productId) {
Optional<Product> product = productRepository.findById(productId);
if(product.isPresent()) {
......@@ -51,12 +53,12 @@ public class ProductController {
}
}
@GetMapping("/products/new")
@GetMapping("/new")
public String newProduct(Product product) {
return "product_form";
}
@GetMapping("/products/{id}/edit")
@GetMapping("/{id}/edit")
public String editProduct(Model model, @PathVariable("id") int productId) {
Optional<Product> product = productRepository.findById(productId);
if(product.isPresent()) {
......@@ -68,7 +70,7 @@ public class ProductController {
}
}
@PostMapping({"/products/new", "/products/{id}/edit"})
@PostMapping({"/new", "/{id}/edit"})
public String saveProduct(
@Valid Product product,
BindingResult bindingResult,
......@@ -104,7 +106,7 @@ public class ProductController {
}
}
@GetMapping("/products/{id}/add-to-basket")
@GetMapping("/{id}/add-to-basket")
public String addToBasket(
@SessionAttribute Basket basket,
@PathVariable("id") int productId,
......@@ -116,7 +118,7 @@ public class ProductController {
return "redirect:" + adresPowrotu;
}
@GetMapping(path="/products/{id}/photo", produces="image/jpeg")
@GetMapping(path="/{id}/photo", produces="image/jpeg")
@ResponseBody
public byte[] readPhoto(@PathVariable("id") int productId) {
return photoUtil.readBytes(productId);
......
......@@ -36,14 +36,14 @@ import javax.validation.constraints.Size;
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
// W celu obserwacji powstawania i usuwania obiektów:
{ System.out.println("!new Product!"); }
// W celu obserwacji powstawania i usuwania obiektów:
// { System.out.println("!new Product!"); }
@Override
protected void finalize() {
System.out.println("Ginie Produkt nr " + productId);
}
// używanie finalize tak, że miałoby wpływać na działanie, jest niezalecane!
// @Override
// protected void finalize() {
// System.out.println("Ginie Produkt nr " + productId);
// }
// Używanie finalize tak, że miałoby wpływać na działanie, jest niezalecane!
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -55,12 +55,12 @@ public class Product implements Serializable {
@NotNull
@DecimalMin("0.01")
@DecimalMax("9999.99") // tylko dla sprawdzenia działania → docelowo wartość ma być większa
@DecimalMax("99999999.99")
private BigDecimal price;
@Column(name = "product_name")
@NotNull
@Size(min=2, max=10) // FIXME
@Size(min=2, max=100)
private String productName;
@DecimalMin("0.00")
......
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