ProductController.java 1.13 KB
package vion.controller;

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")
    public Page<ProductVO> getProductList(ProductDTO productDTO) {
       return productService.getProductList(productDTO);
    }

    @GetMapping("/product")
    public Product getProductByID(@RequestParam Long projectId) {
        return productService.getById(projectId);
    }

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