Skip to content

Commit

Permalink
category operation modified
Browse files Browse the repository at this point in the history
  • Loading branch information
DAKSHAY111 committed May 20, 2023
1 parent 06e2942 commit 54246a4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,32 @@ public ModelAndView getcategory() {
mView.addObject("categories",categories);
return mView;
}
@RequestMapping(value = "sendcategory",method = RequestMethod.POST)
public ModelAndView addCategory(@RequestParam("categoryname") String category_name)
@RequestMapping(value = "categories",method = RequestMethod.POST)
public String addCategory(@RequestParam("categoryname") String category_name)
{
System.out.println(category_name);

Category category = this.categoryService.addCategory(category_name);
if(category.getName().equals(category_name)) {
ModelAndView mView = new ModelAndView("admin/categories");
mView.addObject("msg", "Category added successfully");
return mView;
return "redirect:categories";
}else {
ModelAndView mView = new ModelAndView("admin/categories");
mView.addObject("msg", "failed to add category");
return mView;
return "redirect:categories";
}
}

@GetMapping("/admin/categories/delete")
public ModelAndView removeCategoryDb(@RequestParam("id") int id)
public String removeCategoryDb(@RequestParam("id") int id)
{
this.categoryService.deleteCategory(id);
ModelAndView mView = new ModelAndView("admin/categories");
return mView;
return "redirect:categories";
}

@GetMapping("/admin/categories/update")
public ModelAndView updateCategoryDb(@RequestParam("categoryid") int id, @RequestParam("categoryname") String categoryname)
@GetMapping("categories/update")
public String updateCategoryDb(@RequestParam("categoryid") int id, @RequestParam("categoryname") String categoryname)
{
Category category = this.categoryService.updateCategory(id, categoryname);
ModelAndView mView = new ModelAndView("admin/categories");
return mView;
return "redirect:categories";
}


Expand Down
2 changes: 1 addition & 1 deletion JtProject/src/main/webapp/views/categories.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<form action="sendcategory" method="get">
<form action="categories" method="post">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Add New
Category</h5>
Expand Down

0 comments on commit 54246a4

Please sign in to comment.