k.e.book.ddh.controller.CcAuthGroupController 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.CcAuthGroupAddDTO;
import k.e.book.ddh.entity.CcAuthGroupDO;
import k.e.book.ddh.entity.CcAuthGroupQueryDTO;
import k.e.book.ddh.entity.CcAuthGroupVO;
import k.e.book.ddh.service.CcAuthGroupService;
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 = "CcAuthGroup相关文档")
@RestController
@RequestMapping("/ccAuthGroup")
public class CcAuthGroupController {
@Resource
private CcAuthGroupService ccAuthGroupService;
@ApiOperation("分页查询CcAuthGroup信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcAuthGroupQueryDTO dto) {
IPage page = ccAuthGroupService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcAuthGroupDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcAuthGroup信息")
@GetMapping(value = "/get")
public Result getCcAuthGroupById(@RequestParam("id") @ApiParam(value = "ccAuthGroupD") Long id) {
return Result.success(CcAuthGroupDO.toVO(ccAuthGroupService.getById(id)));
}
@ApiOperation("新增CcAuthGroup")
@PostMapping("/add")
public Result addCcAuthGroup(@RequestBody @Valid CcAuthGroupAddDTO dto) {
CcAuthGroupDO entity = CcAuthGroupDO.toDO(dto);
ccAuthGroupService.save(entity);
return getCcAuthGroupById(entity.getId());
}
@ApiOperation("删除CcAuthGroup")
@DeleteMapping("/delete")
public Result deleteCcAuthGroupById(@RequestParam("id") @ApiParam(value = "ccAuthGroupID") Long id) {
ccAuthGroupService.removeById(id);
return Result.success();
}
}