k.e.book.ddh.controller.CcUserAddressController 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.CcUserAddressAddDTO;
import k.e.book.ddh.entity.CcUserAddressDO;
import k.e.book.ddh.entity.CcUserAddressQueryDTO;
import k.e.book.ddh.entity.CcUserAddressVO;
import k.e.book.ddh.service.CcUserAddressService;
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 = "CcUserAddress相关文档")
@RestController
@RequestMapping("/ccUserAddress")
public class CcUserAddressController {
@Resource
private CcUserAddressService ccUserAddressService;
@ApiOperation("分页查询CcUserAddress信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcUserAddressQueryDTO dto) {
IPage page = ccUserAddressService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcUserAddressDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcUserAddress信息")
@GetMapping(value = "/get")
public Result getCcUserAddressById(@RequestParam("id") @ApiParam(value = "ccUserAddressD") Long id) {
return Result.success(CcUserAddressDO.toVO(ccUserAddressService.getById(id)));
}
@ApiOperation("新增CcUserAddress")
@PostMapping("/add")
public Result addCcUserAddress(@RequestBody @Valid CcUserAddressAddDTO dto) {
CcUserAddressDO entity = CcUserAddressDO.toDO(dto);
ccUserAddressService.save(entity);
return getCcUserAddressById(entity.getId());
}
@ApiOperation("删除CcUserAddress")
@DeleteMapping("/delete")
public Result deleteCcUserAddressById(@RequestParam("id") @ApiParam(value = "ccUserAddressID") Long id) {
ccUserAddressService.removeById(id);
return Result.success();
}
}