diff --git a/src/main/java/me/anant/PMS/config/AuthenticationSuccessHandlerImpl.java b/src/main/java/me/anant/PMS/config/AuthenticationSuccessHandlerImpl.java index 4444a2f..b212d06 100644 --- a/src/main/java/me/anant/PMS/config/AuthenticationSuccessHandlerImpl.java +++ b/src/main/java/me/anant/PMS/config/AuthenticationSuccessHandlerImpl.java @@ -26,7 +26,7 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo Authentication authentication) throws IOException, ServletException { Set roles = AuthorityUtils.authorityListToSet(authentication.getAuthorities()); if (roles.contains("ROLE_ADMIN")) { - response.sendRedirect("/admin/product/list"); + response.sendRedirect("/admin/product"); } else { response.sendRedirect("/customer"); } diff --git a/src/main/java/me/anant/PMS/controller/ProductController.java b/src/main/java/me/anant/PMS/controller/ProductController.java index a770ffb..3957fbd 100644 --- a/src/main/java/me/anant/PMS/controller/ProductController.java +++ b/src/main/java/me/anant/PMS/controller/ProductController.java @@ -1,18 +1,15 @@ package me.anant.PMS.controller; -import java.util.List; -import java.util.Optional; +import java.util.*; import javax.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.support.RedirectAttributes; @@ -21,6 +18,7 @@ import me.anant.PMS.service.ProductService; @Controller +@RequestMapping("/admin/product") public class ProductController { @Autowired ProductService productService; @@ -28,7 +26,7 @@ public class ProductController { @Autowired ProductCategoryService categoryService; - @GetMapping("/admin/product/add") + @GetMapping("/add") public ModelAndView addView() { ModelAndView modelAndView = new ModelAndView("admin/product/add"); modelAndView.addObject("pcList", categoryService.get()); @@ -36,7 +34,7 @@ public ModelAndView addView() { return modelAndView; } - @PostMapping("/admin/product/add") + @PostMapping("/add") public String add(@ModelAttribute("command") @Valid Product product, BindingResult result, Model model, final RedirectAttributes redirectAttributes) { if(result.hasErrors()) { model.addAttribute("pcList", categoryService.get()); @@ -47,13 +45,16 @@ public String add(@ModelAttribute("command") @Valid Product product, BindingResu redirectAttributes.addFlashAttribute("class", "alert-success"); return "redirect:/admin/product/add"; } - - @GetMapping("/admin/product/list") - public ModelAndView list() { + + @GetMapping + public String index() { + return "admin/product/list"; + } + + @GetMapping("/list") + public ResponseEntity> list() { List pList = productService.get(); - ModelAndView modelAndView = new ModelAndView("/admin/product/list"); - modelAndView.addObject("pList", pList); - return modelAndView; + return ResponseEntity.ok(pList); } @GetMapping("/admin/product/delete") @@ -87,7 +88,7 @@ public String updateView(@ModelAttribute("command") @Valid Product product, Bind return "redirect:/admin/product/list"; } - @GetMapping("/admin/product/report") + @GetMapping("/report") public ModelAndView report() { ModelAndView modelAndView = new ModelAndView("admin/product/report"); modelAndView.addObject("pList", productService.get()); diff --git a/src/main/java/me/anant/PMS/model/Product.java b/src/main/java/me/anant/PMS/model/Product.java index 4d3fa01..631e57d 100644 --- a/src/main/java/me/anant/PMS/model/Product.java +++ b/src/main/java/me/anant/PMS/model/Product.java @@ -1,5 +1,7 @@ package me.anant.PMS.model; +import com.fasterxml.jackson.annotation.JsonIgnore; + import java.util.Set; import javax.persistence.CascadeType; @@ -33,13 +35,14 @@ public class Product { @Min(value=0, message="Product quantity can not be negative") @Max(value=50, message="Product quantity can be maximum 50.") int productQty; - + @OneToMany(mappedBy = "product", cascade = CascadeType.ALL) Set orderProduct; + @JsonIgnore @ManyToOne(fetch = FetchType.LAZY) - ProductCategory category; - + ProductCategory category; + public Product() { // TODO Auto-generated constructor stub } diff --git a/src/main/webapp/admin/product/list.jsp b/src/main/webapp/admin/product/list.jsp index 37acf5d..1283046 100644 --- a/src/main/webapp/admin/product/list.jsp +++ b/src/main/webapp/admin/product/list.jsp @@ -11,7 +11,7 @@
@@ -26,25 +26,7 @@ Action - - <% - List pl = (List) request.getAttribute("pList"); - for (Product p : pl) - { - %> - - <%=p.getProductId()%> - <%=p.getProductName()%> - Rs. <%= p.getProductPrice() %> - <%= p.getProductQty() %> - - Edit - Delete - - - <% - } - %> +
@@ -53,4 +35,4 @@ <%@include file="/includes/footer.jsp"%> - \ No newline at end of file + diff --git a/src/main/webapp/includes/footer.jsp b/src/main/webapp/includes/footer.jsp index d4d6468..b8b354b 100644 --- a/src/main/webapp/includes/footer.jsp +++ b/src/main/webapp/includes/footer.jsp @@ -1,32 +1,77 @@ <%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> + pageEncoding="ISO-8859-1" %>
-
- Copyright Reserver © 2020 -
+
+ Copyright Reserver © 2020 +
- - - - - \ No newline at end of file + + + + + diff --git a/src/main/webapp/includes/header.jsp b/src/main/webapp/includes/header.jsp index 8ad0295..88a06e7 100644 --- a/src/main/webapp/includes/header.jsp +++ b/src/main/webapp/includes/header.jsp @@ -9,7 +9,7 @@ PMS - PMS + PMS PMS @@ -22,7 +22,7 @@