k.e.book.ddh.controller.CcUserGroupController 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.CcUserGroupAddDTO;
import k.e.book.ddh.entity.CcUserGroupDO;
import k.e.book.ddh.entity.CcUserGroupQueryDTO;
import k.e.book.ddh.entity.CcUserGroupVO;
import k.e.book.ddh.service.CcUserGroupService;
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 = "CcUserGroup相关文档")
@RestController
@RequestMapping("/ccUserGroup")
public class CcUserGroupController {
@Resource
private CcUserGroupService ccUserGroupService;
@ApiOperation("分页查询CcUserGroup信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcUserGroupQueryDTO dto) {
IPage page = ccUserGroupService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcUserGroupDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcUserGroup信息")
@GetMapping(value = "/get")
public Result getCcUserGroupById(@RequestParam("id") @ApiParam(value = "ccUserGroupD") Long id) {
return Result.success(CcUserGroupDO.toVO(ccUserGroupService.getById(id)));
}
@ApiOperation("新增CcUserGroup")
@PostMapping("/add")
public Result addCcUserGroup(@RequestBody @Valid CcUserGroupAddDTO dto) {
CcUserGroupDO entity = CcUserGroupDO.toDO(dto);
ccUserGroupService.save(entity);
return getCcUserGroupById(entity.getId());
}
@ApiOperation("删除CcUserGroup")
@DeleteMapping("/delete")
public Result deleteCcUserGroupById(@RequestParam("id") @ApiParam(value = "ccUserGroupID") Long id) {
ccUserGroupService.removeById(id);
return Result.success();
}
}