All Downloads are FREE. Search and download functionalities are using the official Maven repository.

k.e.book.ddh.controller.CcProductController Maven / Gradle / Ivy


package k.e.book.ddh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import k.e.book.common.model.Result;
import k.e.book.ddh.entity.CcProductAddDTO;
import k.e.book.ddh.entity.CcProductDO;
import k.e.book.ddh.entity.CcProductQueryDTO;
import k.e.book.ddh.entity.CcProductVO;
import k.e.book.ddh.service.CcProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author kk
 * @date 2023-05-21 11:13
 */

@Api(tags = "CcProduct相关文档")
@RestController
@RequestMapping("/ccProduct")
public class CcProductController {
    @Resource
    private CcProductService ccProductService;

    @ApiOperation("分页查询CcProduct信息")
    @PostMapping(value = "/page")
    public Result> queryPage(@RequestBody @Valid  CcProductQueryDTO dto) {
        IPage page = ccProductService.selectProductPage(dto);
        List records = page.getRecords();
        return Result.success(records.stream().map(CcProductDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
    }

    @ApiOperation("根据 id 查询CcProduct信息")
    @GetMapping(value = "/get")
    public Result getCcProductById(@RequestParam("id") @ApiParam(value = "ccProductD") Long id) {
        return Result.success(CcProductDO.toVO(ccProductService.getById(id)));
    }

    @ApiOperation("新增CcProduct")
    @PostMapping("/add")
    public Result addCcProduct(@RequestBody @Valid CcProductAddDTO dto) {
        CcProductDO entity = CcProductDO.toDO(dto);
        ccProductService.save(entity);
        return getCcProductById(entity.getId());
    }

    @ApiOperation("删除CcProduct")
    @DeleteMapping("/delete")
    public Result deleteCcProductById(@RequestParam("id") @ApiParam(value = "ccProductID") Long id) {
        ccProductService.removeById(id);
        return Result.success();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy