k.e.book.ddh.controller.CcGiveController 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.CcGiveAddDTO;
import k.e.book.ddh.entity.CcGiveDO;
import k.e.book.ddh.entity.CcGiveQueryDTO;
import k.e.book.ddh.entity.CcGiveVO;
import k.e.book.ddh.service.CcGiveService;
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 = "CcGive相关文档")
@RestController
@RequestMapping("/ccGive")
public class CcGiveController {
@Resource
private CcGiveService ccGiveService;
@ApiOperation("分页查询CcGive信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcGiveQueryDTO dto) {
IPage page = ccGiveService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcGiveDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcGive信息")
@GetMapping(value = "/get")
public Result getCcGiveById(@RequestParam("id") @ApiParam(value = "ccGiveD") Long id) {
return Result.success(CcGiveDO.toVO(ccGiveService.getById(id)));
}
@ApiOperation("新增CcGive")
@PostMapping("/add")
public Result addCcGive(@RequestBody @Valid CcGiveAddDTO dto) {
CcGiveDO entity = CcGiveDO.toDO(dto);
ccGiveService.save(entity);
return getCcGiveById(entity.getId());
}
@ApiOperation("删除CcGive")
@DeleteMapping("/delete")
public Result deleteCcGiveById(@RequestParam("id") @ApiParam(value = "ccGiveID") Long id) {
ccGiveService.removeById(id);
return Result.success();
}
}