k.e.book.ddh.controller.CcAreaController 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.CcAreaAddDTO;
import k.e.book.ddh.entity.CcAreaDO;
import k.e.book.ddh.entity.CcAreaQueryDTO;
import k.e.book.ddh.entity.CcAreaVO;
import k.e.book.ddh.service.CcAreaService;
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 = "CcArea相关文档")
@RestController
@RequestMapping("/ccArea")
public class CcAreaController {
@Resource
private CcAreaService ccAreaService;
@ApiOperation("分页查询CcArea信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcAreaQueryDTO dto) {
IPage page = ccAreaService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcAreaDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcArea信息")
@GetMapping(value = "/get")
public Result getCcAreaById(@RequestParam("id") @ApiParam(value = "ccAreaD") Long id) {
return Result.success(CcAreaDO.toVO(ccAreaService.getById(id)));
}
@ApiOperation("新增CcArea")
@PostMapping("/add")
public Result addCcArea(@RequestBody @Valid CcAreaAddDTO dto) {
CcAreaDO entity = CcAreaDO.toDO(dto);
ccAreaService.save(entity);
return getCcAreaById(entity.getId());
}
@ApiOperation("删除CcArea")
@DeleteMapping("/delete")
public Result deleteCcAreaById(@RequestParam("id") @ApiParam(value = "ccAreaID") Long id) {
ccAreaService.removeById(id);
return Result.success();
}
}