k.e.book.ddh.controller.CcBoxProductController 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.CcBoxProductAddDTO;
import k.e.book.ddh.entity.CcBoxProductDO;
import k.e.book.ddh.entity.CcBoxProductQueryDTO;
import k.e.book.ddh.entity.CcBoxProductVO;
import k.e.book.ddh.service.CcBoxProductService;
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 = "CcBoxProduct相关文档")
@RestController
@RequestMapping("/ccBoxProduct")
public class CcBoxProductController {
@Resource
private CcBoxProductService ccBoxProductService;
@ApiOperation("分页查询CcBoxProduct信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcBoxProductQueryDTO dto) {
IPage page = ccBoxProductService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcBoxProductDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcBoxProduct信息")
@GetMapping(value = "/get")
public Result getCcBoxProductById(@RequestParam("id") @ApiParam(value = "ccBoxProductD") Long id) {
return Result.success(CcBoxProductDO.toVO(ccBoxProductService.getById(id)));
}
@ApiOperation("新增CcBoxProduct")
@PostMapping("/add")
public Result addCcBoxProduct(@RequestBody @Valid CcBoxProductAddDTO dto) {
CcBoxProductDO entity = CcBoxProductDO.toDO(dto);
ccBoxProductService.save(entity);
return getCcBoxProductById(entity.getId());
}
@ApiOperation("删除CcBoxProduct")
@DeleteMapping("/delete")
public Result deleteCcBoxProductById(@RequestParam("id") @ApiParam(value = "ccBoxProductID") Long id) {
ccBoxProductService.removeById(id);
return Result.success();
}
}