feat(文章评论功能开发): 文章评论获取调整为公开接口允许所有人访问,不进行可否删除权限判断

This commit is contained in:
OTTO 2023-12-08 09:54:47 +08:00
parent f982494346
commit 475e097a4f
4 changed files with 43 additions and 36 deletions

View File

@ -6,7 +6,9 @@ import com.ruoyi.cms.doc.domain.CmsDocCommentUpdateDto;
import com.ruoyi.cms.doc.service.ICmsDocCommentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import io.swagger.annotations.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@ -63,19 +65,4 @@ public class CmsDocCommentController extends BaseController {
return success(result);
}
/**
* 获取文章下评论列表
*/
@GetMapping("/{docId}/list")
@ApiOperation(value = "获取文章下评论列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "limit", value = "分页数", paramType = "query", dataType = "Integer"),
})
public AjaxResult getCommentList(
@ApiParam("文章Id") @PathVariable Long docId, Integer page, Integer limit) {
JSONObject result = cmsDocCommentService.getCommentList(docId, page, limit);
return success(result);
}
}

View File

@ -1,6 +1,8 @@
package com.ruoyi.cms.doc.controller;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.cms.doc.domain.*;
import com.ruoyi.cms.doc.service.ICmsDocCommentService;
import com.ruoyi.cms.doc.service.ICmsDocService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
@ -26,6 +28,8 @@ import java.util.List;
public class OpenController extends BaseController {
@Autowired
private ICmsDocService cmsDocService;
@Autowired
private ICmsDocCommentService cmsDocCommentService;
/**
* 查询栏目列表
@ -163,5 +167,21 @@ public class OpenController extends BaseController {
cmsDocService.syncDocData(deptId,bodyStr);
return AjaxResult.success("同步消息发送成功");
}
/**
* 公开获取文章下评论列表
*/
@GetMapping("/{docId}/journalList")
@ApiOperation(value = "公开获取文章下评论列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "limit", value = "分页数", paramType = "query", dataType = "Integer"),
})
public AjaxResult getCommentList(
@ApiParam("文章Id") @PathVariable Long docId, Integer page, Integer limit) {
JSONObject result = cmsDocCommentService.getCommentList(docId, page, limit);
return success(result);
}
}

View File

@ -82,24 +82,24 @@ public class CmsDocCommentServiceImpl implements ICmsDocCommentService {
page, limit
));
JSONArray journals = journalDataJson.getJSONArray("journals");
if (journals != null) {
// 设置评论可删除权限
for (int i = 0; i < journals.size(); i++) {
JSONObject journal = journals.getJSONObject(i);
setJournalCanDelete(cmsDoc, journal);
journals.set(i, journal);
// 检查评论是否存在回复
JSONArray childrenJournals = journal.getJSONArray("children_journals");
if (childrenJournals != null) {
for (int j = 0; j < childrenJournals.size(); j++) {
JSONObject childrenJournal = childrenJournals.getJSONObject(j);
setJournalCanDelete(cmsDoc, childrenJournal);
childrenJournals.set(j, childrenJournal);
}
journal.put("children_journals", childrenJournals);
}
}
}
// if (journals != null) {
// // 设置评论可删除权限
// for (int i = 0; i < journals.size(); i++) {
// JSONObject journal = journals.getJSONObject(i);
// setJournalCanDelete(cmsDoc, journal);
// journals.set(i, journal);
// // 检查评论是否存在回复
// JSONArray childrenJournals = journal.getJSONArray("children_journals");
// if (childrenJournals != null) {
// for (int j = 0; j < childrenJournals.size(); j++) {
// JSONObject childrenJournal = childrenJournals.getJSONObject(j);
// setJournalCanDelete(cmsDoc, childrenJournal);
// childrenJournals.set(j, childrenJournal);
// }
// journal.put("children_journals", childrenJournals);
// }
// }
// }
journalDataJson.put("journals", journals);
return journalDataJson;
}

View File

@ -177,11 +177,11 @@ public class CmsGitLinkRequestUrl extends GitLinkRequestUrl {
}
public static GitLinkRequestUrl GET_ISSUE(String username, String identifier, Long issueId) {
return getGitLinkRequestUrl(String.format("/api/v1/%s/%s/issues/%d", username, identifier, issueId));
return getOpenGitLinkRequestUrl(String.format("/api/v1/%s/%s/issues/%d", username, identifier, issueId));
}
public static GitLinkRequestUrl GET_JOURNALS(String username, String identifier, Long issueId, Integer page, Integer limit) {
return getGitLinkRequestUrl(String.format("/api/v1/%s/%s/issues/%d/journals?category=comment&page=%d&limit=%d", username, identifier, issueId, page, limit));
return getOpenGitLinkRequestUrl(String.format("/api/v1/%s/%s/issues/%d/journals?category=comment&page=%d&limit=%d", username, identifier, issueId, page, limit));
}
public static GitLinkRequestUrl DELETE_AND_UPDATE_JOURNAL(String username, String identifier, Long issueId, Long journalId) {