Skip to content

Commit

Permalink
🦄 fix delete comment content not update
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Feb 26, 2017
1 parent 2da5569 commit a8f16c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.blade.mvc.http.Request;
import com.blade.mvc.view.RestResponse;
import com.tale.controller.BaseController;
import com.tale.dto.Comment;
import com.tale.exception.TipException;
import com.tale.model.Comments;
import com.tale.model.Users;
Expand Down Expand Up @@ -50,7 +51,11 @@ public String index(@QueryParam(value = "page", defaultValue = "1") int page,
@JSON
public RestResponse delete(@QueryParam Integer coid) {
try {
commentsService.delete(coid);
Comments comments = commentsService.byId(coid);
if(null == comments){
return RestResponse.fail("不存在该评论");
}
commentsService.delete(coid, comments.getCid());
} catch (Exception e) {
String msg = "评论删除失败";
if (e instanceof TipException) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/tale/service/CommentsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public interface CommentsService {
/**
* 删除评论,暂时没用
* @param coid
* @param cid
* @throws Exception
*/
void delete(Integer coid) throws Exception;
void delete(Integer coid, Integer cid);

/**
* 获取文章下的评论
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/tale/service/ContentsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public interface ContentsService {
*/
void updateArticle(Contents contents);

/**
* 自定义update
* @param contents
*/
void update(Contents contents);

/**
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/tale/service/impl/CommentsServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.tale.model.Comments;
import com.tale.model.Contents;
import com.tale.service.CommentsService;
import com.tale.service.ContentsService;
import com.tale.utils.TaleUtils;

import java.util.ArrayList;
Expand All @@ -24,6 +25,9 @@ public class CommentsServiceImpl implements CommentsService {
@Inject
private ActiveRecord activeRecord;

@Inject
private ContentsService contentsService;

@Override
public void saveComment(Comments comments) {
if (null == comments) {
Expand Down Expand Up @@ -66,12 +70,19 @@ public void saveComment(Comments comments) {
}

@Override
public void delete(Integer coid) throws Exception {
public void delete(Integer coid, Integer cid){
if (null == coid) {
throw new TipException("主键为空");
}
try {
activeRecord.delete(Comments.class, coid);
Contents contents = contentsService.getContents(cid+"");
if(null != contents && contents.getComments_num() > 0){
Contents temp = new Contents();
temp.setCid(cid);
temp.setComments_num(contents.getComments_num() - 1);
contentsService.update(temp);
}
} catch (Exception e) {
throw e;
}
Expand Down

0 comments on commit a8f16c1

Please sign in to comment.