[e9b70f6] | 1 | package com.example.salonbella.controller.product;
|
---|
| 2 |
|
---|
| 3 | import com.example.salonbella.service.ProductService;
|
---|
| 4 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 5 | import org.springframework.stereotype.Controller;
|
---|
| 6 | import org.springframework.ui.Model;
|
---|
| 7 | import org.springframework.web.bind.annotation.GetMapping;
|
---|
| 8 | import org.springframework.web.bind.annotation.PostMapping;
|
---|
| 9 | import org.springframework.web.bind.annotation.RequestParam;
|
---|
| 10 | import org.springframework.web.multipart.MultipartFile;
|
---|
| 11 |
|
---|
| 12 | import java.io.IOException;
|
---|
| 13 |
|
---|
| 14 | @Controller
|
---|
| 15 | public 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 | }
|
---|
| 57 |
|
---|