ProductController.java 1.37 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.dto.ProductDTO;
import vion.model.Product;
import vion.service.IProductService;
import vion.vo.ProductVO;

@RestController
@RequestMapping(Global.BASE_URL)
@RequiredArgsConstructor
@Slf4j
public class ProductController {

    private final IProductService productService;
    private final Converter converter;

    @GetMapping("/products")
    @SaCheckPermission(value = "product:list", orRole="admin")
    public Page<ProductVO> getProductList(ProductDTO productDTO) {
       return productService.getProductList(productDTO);
    }

    @GetMapping("/product")
    @SaCheckPermission(value = "product:query", orRole="admin")
    public Product getProductByID(@RequestParam Long projectId) {
        return productService.getById(projectId);
    }

    @PostMapping("/products")
    @SaCheckPermission(value = "product:editAndSave", orRole="admin")
    public String saveOrUpdate(@RequestBody ProductDTO productDTO) {
        Product data = converter.convert(productDTO, new Product());
        return productService.saveOrUpdate(data) ? "成功" : "失败";
    }
}