k.e.book.ddh.controller.CcAirdropController 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.CcAirdropAddDTO;
import k.e.book.ddh.entity.CcAirdropDO;
import k.e.book.ddh.entity.CcAirdropQueryDTO;
import k.e.book.ddh.entity.CcAirdropVO;
import k.e.book.ddh.service.CcAirdropService;
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 = "CcAirdrop相关文档")
@RestController
@RequestMapping("/ccAirdrop")
public class CcAirdropController {
@Resource
private CcAirdropService ccAirdropService;
@ApiOperation("分页查询CcAirdrop信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcAirdropQueryDTO dto) {
IPage page = ccAirdropService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcAirdropDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcAirdrop信息")
@GetMapping(value = "/get")
public Result getCcAirdropById(@RequestParam("id") @ApiParam(value = "ccAirdropD") Long id) {
return Result.success(CcAirdropDO.toVO(ccAirdropService.getById(id)));
}
@ApiOperation("新增CcAirdrop")
@PostMapping("/add")
public Result addCcAirdrop(@RequestBody @Valid CcAirdropAddDTO dto) {
CcAirdropDO entity = CcAirdropDO.toDO(dto);
ccAirdropService.save(entity);
return getCcAirdropById(entity.getId());
}
@ApiOperation("删除CcAirdrop")
@DeleteMapping("/delete")
public Result deleteCcAirdropById(@RequestParam("id") @ApiParam(value = "ccAirdropID") Long id) {
ccAirdropService.removeById(id);
return Result.success();
}
}