k.e.book.ddh.controller.CcAlbumController 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.CcAlbumAddDTO;
import k.e.book.ddh.entity.CcAlbumDO;
import k.e.book.ddh.entity.CcAlbumQueryDTO;
import k.e.book.ddh.entity.CcAlbumVO;
import k.e.book.ddh.service.CcAlbumService;
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 = "CcAlbum相关文档")
@RestController
@RequestMapping("/ccAlbum")
public class CcAlbumController {
@Resource
private CcAlbumService ccAlbumService;
@ApiOperation("分页查询CcAlbum信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcAlbumQueryDTO dto) {
IPage page = ccAlbumService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcAlbumDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcAlbum信息")
@GetMapping(value = "/get")
public Result getCcAlbumById(@RequestParam("id") @ApiParam(value = "ccAlbumD") Long id) {
return Result.success(CcAlbumDO.toVO(ccAlbumService.getById(id)));
}
@ApiOperation("新增CcAlbum")
@PostMapping("/add")
public Result addCcAlbum(@RequestBody @Valid CcAlbumAddDTO dto) {
CcAlbumDO entity = CcAlbumDO.toDO(dto);
ccAlbumService.save(entity);
return getCcAlbumById(entity.getId());
}
@ApiOperation("删除CcAlbum")
@DeleteMapping("/delete")
public Result deleteCcAlbumById(@RequestParam("id") @ApiParam(value = "ccAlbumID") Long id) {
ccAlbumService.removeById(id);
return Result.success();
}
}