k.e.book.ddh.controller.CcConfigController 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.CcConfigAddDTO;
import k.e.book.ddh.entity.CcConfigDO;
import k.e.book.ddh.entity.CcConfigQueryDTO;
import k.e.book.ddh.entity.CcConfigVO;
import k.e.book.ddh.service.CcConfigService;
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 = "CcConfig相关文档")
@RestController
@RequestMapping("/ccConfig")
public class CcConfigController {
@Resource
private CcConfigService ccConfigService;
@ApiOperation("分页查询CcConfig信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcConfigQueryDTO dto) {
IPage page = ccConfigService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcConfigDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcConfig信息")
@GetMapping(value = "/get")
public Result getCcConfigById(@RequestParam("id") @ApiParam(value = "ccConfigD") Long id) {
return Result.success(CcConfigDO.toVO(ccConfigService.getById(id)));
}
@ApiOperation("新增CcConfig")
@PostMapping("/add")
public Result addCcConfig(@RequestBody @Valid CcConfigAddDTO dto) {
CcConfigDO entity = CcConfigDO.toDO(dto);
ccConfigService.save(entity);
return getCcConfigById(entity.getId());
}
@ApiOperation("删除CcConfig")
@DeleteMapping("/delete")
public Result deleteCcConfigById(@RequestParam("id") @ApiParam(value = "ccConfigID") Long id) {
ccConfigService.removeById(id);
return Result.success();
}
}