source: src/main/java/com/example/salonbella/controller/product/ProductController.java@ 4d7e387

Last change on this file since 4d7e387 was 4d7e387, checked in by makyjovanovsky <mjovanovski04@…>, 18 months ago

commit 1

  • Property mode set to 100644
File size: 1.8 KB
Line 
1package com.example.salonbella.controller.product;
2
3import com.example.salonbella.service.ProductService;
4import org.springframework.beans.factory.annotation.Autowired;
5import org.springframework.stereotype.Controller;
6import org.springframework.ui.Model;
7import org.springframework.web.bind.annotation.GetMapping;
8import org.springframework.web.bind.annotation.PostMapping;
9import org.springframework.web.bind.annotation.RequestParam;
10import org.springframework.web.multipart.MultipartFile;
11
12import java.io.IOException;
13
14@Controller
15public class ProductController {
16
17 private final ProductService productService;
18
19
20 @Autowired
21 public ProductController(ProductService productService) {
22 this.productService = productService;
23
24 }
25
26
27 @GetMapping("/admin-add-product")
28 public String getAddProductPage() {
29 return "admin-product";
30 }
31
32 @PostMapping("/admin-add-product")
33 public String addProduct(@RequestParam(name = "name") String name, @RequestParam(name = "category") String category,
34 @RequestParam(name = "price") String price,
35 @RequestParam(name = "description") String description,
36 @RequestParam(name = "image") MultipartFile multipartFile) throws IOException {
37 productService.addProduct(name, category, price, description, multipartFile);
38 return "redirect:/adminDashboard";
39 }
40
41
42
43 @GetMapping("/admin-remove-product")
44 public String getRemoveProductPage(Model model) {
45 model.addAttribute("products", productService.getProducts());
46 return "admin-remove-product";
47 }
48
49 @PostMapping("/admin-remove-product")
50 public String removeProduct(@RequestParam(name = "id") String id) {
51 productService.removeProduct(Long.parseLong(id));
52 return "redirect:/admin-remove-product";
53 }
54
55
56}
Note: See TracBrowser for help on using the repository browser.