Commit 42a90ba7 by Patryk Czarnik

Koszyk w wersji @SessionAttribute

parent e88099ad
...@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.PathVariable; ...@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttribute;
import sklep.basket.Basket; import sklep.basket.Basket;
import sklep.model.Product; import sklep.model.Product;
...@@ -136,8 +137,7 @@ public class ProductController { ...@@ -136,8 +137,7 @@ public class ProductController {
@GetMapping("/{id}/add-to-basket") @GetMapping("/{id}/add-to-basket")
public String addToBasket( public String addToBasket(
@PathVariable("id") int productId, @PathVariable("id") int productId,
HttpSession sesja) { @SessionAttribute Basket basket) {
Basket basket = (Basket) sesja.getAttribute("basket");
Optional<Product> product = productRepository.findById(productId); Optional<Product> product = productRepository.findById(productId);
if(product.isPresent()) { if(product.isPresent()) {
basket.addProduct(product.get()); basket.addProduct(product.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