package com.mzl.flower.web.v2.comment;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.mzl.flower.base.BaseController;
|
import com.mzl.flower.base.R;
|
import com.mzl.flower.base.ReturnDataDTO;
|
import com.mzl.flower.config.exception.ValidationException;
|
import com.mzl.flower.dto.request.comment.*;
|
import com.mzl.flower.dto.response.comment.FlowerCommentVO;
|
import com.mzl.flower.dto.response.coupon.CouponTemplatePointVO;
|
import com.mzl.flower.dto.response.coupon.CouponTemplateVO;
|
import com.mzl.flower.service.comment.FlowerCommentService;
|
import com.mzl.flower.utils.ConverterUtil;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
import com.mzl.flower.entity.FlowerCommentDO;
|
|
|
/**
|
* 商品评论表前端控制器
|
*
|
* @author @TaoJie
|
* @since 2024-09-29
|
*/
|
@RestController
|
@RequestMapping("/api/v2/flower-comment")
|
@Api(value = "商品评论", tags = "商品评论")
|
@Validated
|
public class FlowerCommentController extends BaseController {
|
|
@Autowired
|
private FlowerCommentService flowerCommentService;
|
|
@PostMapping("")
|
@ApiOperation(value = "新增", notes = "新增")
|
public ResponseEntity<ReturnDataDTO> create(@Validated @RequestBody CreateFlowerCommentDTO dto) {
|
|
// 信息验证
|
valid(dto);
|
flowerCommentService.createFlowerComment(dto);
|
return returnData(R.SUCCESS.getCode(), null);
|
|
|
}
|
|
@PostMapping("/batch")
|
@ApiOperation(value = "批量新增", notes = "批量新增")
|
public ResponseEntity<ReturnDataDTO> createBatch(@Validated @RequestBody CreateFlowerCommentBatchDTO dto) {
|
|
//
|
flowerCommentService.createFlowerCommentBatch(dto);
|
return returnData(R.SUCCESS.getCode(), null);
|
|
|
}
|
|
@PutMapping("/{id}")
|
@ApiOperation(value = "修改", notes = "修改")
|
public ResponseEntity<ReturnDataDTO> update(@PathVariable String id,@Validated @RequestBody UpdateFlowerCommentDTO dto) {
|
|
// 手动设置id值
|
dto.setId(id);
|
flowerCommentService.updateFlowerComment(dto);
|
return returnData(R.SUCCESS.getCode(), null);
|
}
|
|
@DeleteMapping("/{id}")
|
@ApiOperation(value = "删除", notes = "删除")
|
public ResponseEntity<ReturnDataDTO> delete(@PathVariable String id) {
|
|
FlowerCommentDO flowerCommentDO = flowerCommentService.getById(id);
|
if (null == flowerCommentDO) {
|
throw new ValidationException("评论不存在");
|
}
|
flowerCommentService.deleteFlowerComment(id);
|
return returnData(R.SUCCESS.getCode(), null);
|
}
|
|
@GetMapping("/{id}")
|
@ApiOperation(value = "详情", notes = "详情")
|
public ResponseEntity<ReturnDataDTO> get(@PathVariable String id) {
|
FlowerCommentVO flowerCommentVO = flowerCommentService.getDetailById(id);
|
return returnData(R.SUCCESS.getCode(), ConverterUtil.transObject(flowerCommentVO, FlowerCommentVO.class));
|
}
|
|
@GetMapping("/page")
|
@ApiOperation(value = "查询-分页", notes = "查询-分页")
|
public ResponseEntity<ReturnDataDTO<Page<CouponTemplatePointVO>>> page(Page page, QueryFlowerCommentDTO dto) {
|
// 设置只查询活动优惠券的
|
|
Page<FlowerCommentVO> resultPage = flowerCommentService.getPage(page, dto);
|
return returnData(R.SUCCESS.getCode(), ConverterUtil.transPage(resultPage, FlowerCommentVO.class));
|
}
|
|
@GetMapping("/list")
|
@ApiOperation(value = "查询-全部", notes = "查询-全部")
|
public ResponseEntity<ReturnDataDTO<Page<CouponTemplateVO>>> list(QueryFlowerCommentDTO dto) {
|
// 设置只查询活动优惠券的
|
|
return returnData(R.SUCCESS.getCode(), ConverterUtil.transList(flowerCommentService.getList(dto), FlowerCommentVO.class));
|
}
|
|
@GetMapping("/avg/{id}")
|
@ApiOperation(value = "平均分", notes = "平均分")
|
public ResponseEntity<ReturnDataDTO> getCommentAvg(@PathVariable Long id) {
|
return returnData(R.SUCCESS.getCode(), flowerCommentService.getSupplierAvgScore(id));
|
}
|
|
@GetMapping("/statis/{id}")
|
@ApiOperation(value = "统计", notes = "统计")
|
public ResponseEntity<ReturnDataDTO> getStatis(@PathVariable Long id) {
|
return returnData(R.SUCCESS.getCode(), flowerCommentService.getSupplierStatis(id));
|
}
|
|
@PutMapping("/show/{id}")
|
@ApiOperation(value = "显示/隐藏", notes = "显示/隐藏")
|
public ResponseEntity<ReturnDataDTO> updateShow(@PathVariable String id,@Validated @RequestBody ShowFlowerCommentDTO dto) {
|
|
// 手动设置id值
|
dto.setId(id);
|
flowerCommentService.updateShowFlowerComment(dto);
|
return returnData(R.SUCCESS.getCode(), null);
|
}
|
|
@PutMapping("/replay/{id}")
|
@ApiOperation(value = "评论回复", notes = "评论回复")
|
public ResponseEntity<ReturnDataDTO> updateReplay(@PathVariable String id,@Validated @RequestBody ReplayFlowerCommentDTO dto) {
|
|
// 手动设置id值
|
dto.setId(id);
|
flowerCommentService.updateReplayFlowerComment(dto);
|
return returnData(R.SUCCESS.getCode(), null);
|
}
|
|
private void valid(CreateFlowerCommentDTO dto){
|
|
}
|
|
}
|