k.e.book.ddh.controller.CcBoxMarketController 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.CcBoxMarketAddDTO;
import k.e.book.ddh.entity.CcBoxMarketDO;
import k.e.book.ddh.entity.CcBoxMarketQueryDTO;
import k.e.book.ddh.entity.CcBoxMarketVO;
import k.e.book.ddh.service.CcBoxMarketService;
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 = "CcBoxMarket相关文档")
@RestController
@RequestMapping("/ccBoxMarket")
public class CcBoxMarketController {
@Resource
private CcBoxMarketService ccBoxMarketService;
@ApiOperation("分页查询CcBoxMarket信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcBoxMarketQueryDTO dto) {
IPage page = ccBoxMarketService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcBoxMarketDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcBoxMarket信息")
@GetMapping(value = "/get")
public Result getCcBoxMarketById(@RequestParam("id") @ApiParam(value = "ccBoxMarketD") Long id) {
return Result.success(CcBoxMarketDO.toVO(ccBoxMarketService.getById(id)));
}
@ApiOperation("新增CcBoxMarket")
@PostMapping("/add")
public Result addCcBoxMarket(@RequestBody @Valid CcBoxMarketAddDTO dto) {
CcBoxMarketDO entity = CcBoxMarketDO.toDO(dto);
ccBoxMarketService.save(entity);
return getCcBoxMarketById(entity.getId());
}
@ApiOperation("删除CcBoxMarket")
@DeleteMapping("/delete")
public Result deleteCcBoxMarketById(@RequestParam("id") @ApiParam(value = "ccBoxMarketID") Long id) {
ccBoxMarketService.removeById(id);
return Result.success();
}
}