k.e.book.ddh.controller.CcAttachmentController 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.CcAttachmentAddDTO;
import k.e.book.ddh.entity.CcAttachmentDO;
import k.e.book.ddh.entity.CcAttachmentQueryDTO;
import k.e.book.ddh.entity.CcAttachmentVO;
import k.e.book.ddh.service.CcAttachmentService;
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 = "CcAttachment相关文档")
@RestController
@RequestMapping("/ccAttachment")
public class CcAttachmentController {
@Resource
private CcAttachmentService ccAttachmentService;
@ApiOperation("分页查询CcAttachment信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcAttachmentQueryDTO dto) {
IPage page = ccAttachmentService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcAttachmentDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcAttachment信息")
@GetMapping(value = "/get")
public Result getCcAttachmentById(@RequestParam("id") @ApiParam(value = "ccAttachmentD") Long id) {
return Result.success(CcAttachmentDO.toVO(ccAttachmentService.getById(id)));
}
@ApiOperation("新增CcAttachment")
@PostMapping("/add")
public Result addCcAttachment(@RequestBody @Valid CcAttachmentAddDTO dto) {
CcAttachmentDO entity = CcAttachmentDO.toDO(dto);
ccAttachmentService.save(entity);
return getCcAttachmentById(entity.getId());
}
@ApiOperation("删除CcAttachment")
@DeleteMapping("/delete")
public Result deleteCcAttachmentById(@RequestParam("id") @ApiParam(value = "ccAttachmentID") Long id) {
ccAttachmentService.removeById(id);
return Result.success();
}
}