k.e.book.ddh.controller.CcUserGuildController 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.CcUserGuildAddDTO;
import k.e.book.ddh.entity.CcUserGuildDO;
import k.e.book.ddh.entity.CcUserGuildQueryDTO;
import k.e.book.ddh.entity.CcUserGuildVO;
import k.e.book.ddh.service.CcUserGuildService;
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 = "CcUserGuild相关文档")
@RestController
@RequestMapping("/ccUserGuild")
public class CcUserGuildController {
@Resource
private CcUserGuildService ccUserGuildService;
@ApiOperation("分页查询CcUserGuild信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcUserGuildQueryDTO dto) {
IPage page = ccUserGuildService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcUserGuildDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcUserGuild信息")
@GetMapping(value = "/get")
public Result getCcUserGuildById(@RequestParam("id") @ApiParam(value = "ccUserGuildD") Long id) {
return Result.success(CcUserGuildDO.toVO(ccUserGuildService.getById(id)));
}
@ApiOperation("新增CcUserGuild")
@PostMapping("/add")
public Result addCcUserGuild(@RequestBody @Valid CcUserGuildAddDTO dto) {
CcUserGuildDO entity = CcUserGuildDO.toDO(dto);
ccUserGuildService.save(entity);
return getCcUserGuildById(entity.getId());
}
@ApiOperation("删除CcUserGuild")
@DeleteMapping("/delete")
public Result deleteCcUserGuildById(@RequestParam("id") @ApiParam(value = "ccUserGuildID") Long id) {
ccUserGuildService.removeById(id);
return Result.success();
}
}