k.e.book.ddh.controller.CcProductFollowController 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.CcProductFollowAddDTO;
import k.e.book.ddh.entity.CcProductFollowDO;
import k.e.book.ddh.entity.CcProductFollowQueryDTO;
import k.e.book.ddh.entity.CcProductFollowVO;
import k.e.book.ddh.service.CcProductFollowService;
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 = "CcProductFollow相关文档")
@RestController
@RequestMapping("/ccProductFollow")
public class CcProductFollowController {
@Resource
private CcProductFollowService ccProductFollowService;
@ApiOperation("分页查询CcProductFollow信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcProductFollowQueryDTO dto) {
IPage page = ccProductFollowService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcProductFollowDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcProductFollow信息")
@GetMapping(value = "/get")
public Result getCcProductFollowById(@RequestParam("id") @ApiParam(value = "ccProductFollowD") Long id) {
return Result.success(CcProductFollowDO.toVO(ccProductFollowService.getById(id)));
}
@ApiOperation("新增CcProductFollow")
@PostMapping("/add")
public Result addCcProductFollow(@RequestBody @Valid CcProductFollowAddDTO dto) {
CcProductFollowDO entity = CcProductFollowDO.toDO(dto);
ccProductFollowService.save(entity);
return getCcProductFollowById(entity.getId());
}
@ApiOperation("删除CcProductFollow")
@DeleteMapping("/delete")
public Result deleteCcProductFollowById(@RequestParam("id") @ApiParam(value = "ccProductFollowID") Long id) {
ccProductFollowService.removeById(id);
return Result.success();
}
}