You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.7 KiB
Java
101 lines
3.7 KiB
Java
package com.bsd.cases.controller;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.bsd.cases.service.CaseContentCommentsService;
|
|
import com.bsd.cases.util.AjaxRequest;
|
|
import com.bsd.cases.util.AjaxResult;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
@CrossOrigin
|
|
@RestController
|
|
@RequestMapping("/case-content-comments")
|
|
public class CaseContentCommentsController {
|
|
|
|
@Resource
|
|
private CaseContentCommentsService caseContentCommentsService;
|
|
|
|
@RequestMapping("/get-comments-by-content-id")
|
|
public AjaxResult getCaseContentCommentsByContentId(@RequestBody AjaxRequest ajaxRequest, HttpServletRequest request) {
|
|
AjaxResult ajaxResult = new AjaxResult();
|
|
JSONObject data = ajaxRequest.getData();
|
|
if (null == data){
|
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
|
ajaxResult.setRetmsg("data missing");
|
|
}else {
|
|
Integer pageNum = data.getInteger("pageNum");
|
|
Integer pageSize = data.getInteger("pageSize");
|
|
if (null==pageNum|| null == pageSize){
|
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
|
ajaxResult.setRetmsg("分页参数不可为空");
|
|
}else {
|
|
Long contentId = data.getLong("contentId");
|
|
ajaxResult.setRetcode(AjaxResult.SUCCESS);
|
|
ajaxResult.setData(caseContentCommentsService.getCaseContentCommentsByContentId(contentId,pageNum,pageSize));
|
|
}
|
|
}
|
|
return ajaxResult;
|
|
}
|
|
|
|
/**
|
|
* 新增评论
|
|
* @param ajaxRequest
|
|
* @param request
|
|
* @return
|
|
*/
|
|
@RequestMapping("/add-comments")
|
|
public AjaxResult addComments(@RequestBody AjaxRequest ajaxRequest, HttpServletRequest request) {
|
|
AjaxResult ajaxResult = new AjaxResult();
|
|
JSONObject data = ajaxRequest.getData();
|
|
if (null == data){
|
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
|
ajaxResult.setRetmsg("data missing");
|
|
}else {
|
|
Long contentId = data.getLong("contentId");
|
|
String comments = data.getString("comments");
|
|
if (null == contentId){
|
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
|
ajaxResult.setRetmsg("文章id不可为空");
|
|
}else {
|
|
if (StringUtils.isBlank(comments)){
|
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
|
ajaxResult.setRetmsg("文章评论内容不可为空");
|
|
}
|
|
}
|
|
ajaxResult =caseContentCommentsService.addComments(contentId,comments);
|
|
}
|
|
return ajaxResult;
|
|
}
|
|
|
|
/**
|
|
* 删除评论
|
|
* @param ajaxRequest
|
|
* @param request
|
|
* @return
|
|
*/
|
|
@RequestMapping("/del-comments")
|
|
public AjaxResult delComments(@RequestBody AjaxRequest ajaxRequest, HttpServletRequest request) {
|
|
AjaxResult ajaxResult = new AjaxResult();
|
|
JSONObject data = ajaxRequest.getData();
|
|
if (null == data){
|
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
|
ajaxResult.setRetmsg("data missing");
|
|
}else {
|
|
Long commentsId = data.getLong("contentId");
|
|
if (null == commentsId){
|
|
ajaxResult.setRetcode(AjaxResult.FAILED);
|
|
ajaxResult.setRetmsg("评论id不可为空");
|
|
}else {
|
|
ajaxResult =caseContentCommentsService.delComments(commentsId);
|
|
}
|
|
}
|
|
return ajaxResult;
|
|
}
|
|
}
|