Skip to content

Commit

Permalink
🩹 fixed go to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
Petrovich-A committed Jul 11, 2023
1 parent 2025410 commit e52daca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/main/java/by/petrovich/eshop/controller/GoToController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package by.petrovich.eshop.controller;

import by.petrovich.eshop.dto.CartDto;
import by.petrovich.eshop.service.CategoryService;
import by.petrovich.eshop.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import static by.petrovich.eshop.utils.PageName.ADMIN_PAGE;
Expand All @@ -18,10 +20,16 @@

@RestController
@RequiredArgsConstructor
@SessionAttributes({"cartDto"})
public class GoToController {
private final CategoryService categoryService;
private final UserService userService;

@ModelAttribute("cartDto")
public CartDto initializeCartSessionObject() {
return new CartDto();
}

@GetMapping("/home")
public ModelAndView showHomePage() {
ModelMap model = new ModelMap();
Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/templates/cart.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE HTML>
<html lang="en" xmlns:th="https://www.thymeleaf.org">
<html lang="en" xmlns:th="https://www.thymeleaf.org"
xmlns:sec="https://www.thymeleaf.org/thymeleaf-extras-springsecurity6">
<head>
<title>Cart page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
Expand All @@ -14,7 +15,7 @@ <h2>Shopping Cart</h2>
<button type="submit" class="clear-cart-btn">Clear cart</button>
</form>
<div class="shopping-cart">
<p th:text="${user.name}"></p>
<p sec:authentication="principal.username"></p>
<div class="column-labels">
<label class="product-image">Image</label>
<label class="product-name">Name</label>
Expand Down

0 comments on commit e52daca

Please sign in to comment.