Commit 4ff35443 authored by Liang Ding's avatar Liang Ding

🔥 #12764 删除评论接口

parent 13653c4c
......@@ -58,7 +58,7 @@ import javax.servlet.http.HttpSessionEvent;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Vanessa</a>
* @version 1.11.0.14, Mar 31, 2019
* @version 1.11.0.15, Apr 18, 2019
* @since 0.3.1
*/
public final class SoloServletListener extends AbstractServletListener {
......@@ -361,11 +361,9 @@ public final class SoloServletListener extends AbstractServletListener {
DispatcherServlet.get("/console/categories/{page}/{pageSize}/{windowSize}", categoryConsole::getCategories);
final CommentConsole commentConsole = beanManager.getReference(CommentConsole.class);
DispatcherServlet.delete("/console/page/comment/{id}", commentConsole::removePageComment);
DispatcherServlet.delete("/console/article/comment/{id}", commentConsole::removeArticleComment);
DispatcherServlet.get("/console/comments/{page}/{pageSize}/{windowSize}", commentConsole::getComments);
DispatcherServlet.get("/console/comments/article/{id}", commentConsole::getArticleComments);
DispatcherServlet.get("/console/comments/page/{id}", commentConsole::getPageComments);
final LinkConsole linkConsole = beanManager.getReference(LinkConsole.class);
DispatcherServlet.delete("/console/link/{id}", linkConsole::removeLink);
......
......@@ -39,7 +39,7 @@ import java.util.List;
* Comment console request processing.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.5, Dec 11, 2018
* @version 1.1.0.0, Apr 18, 2019
* @since 0.4.0
*/
@RequestProcessor
......@@ -69,48 +69,6 @@ public class CommentConsole {
@Inject
private LangPropsService langPropsService;
/**
* Removes a comment of an article by the specified request.
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "msg": ""
* }
* </pre>
* </p>
*
* @param context the specified request context
*/
public void removePageComment(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
context.setRenderer(renderer);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
try {
final String commentId = context.pathVar("id");
final JSONObject currentUser = Solos.getCurrentUser(context.getRequest(), context.getResponse());
if (!commentQueryService.canAccessComment(commentId, currentUser)) {
ret.put(Keys.STATUS_CODE, false);
ret.put(Keys.MSG, langPropsService.get("forbiddenLabel"));
return;
}
commentMgmtService.removePageComment(commentId);
ret.put(Keys.STATUS_CODE, true);
ret.put(Keys.MSG, langPropsService.get("removeSuccLabel"));
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
ret.put(Keys.STATUS_CODE, false);
ret.put(Keys.MSG, langPropsService.get("removeFailLabel"));
}
}
/**
* Removes a comment of an article by the specified request.
* <p>
......@@ -251,48 +209,4 @@ public class CommentConsole {
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
/**
* Gets comments of a page specified by the article id for administrator.
* <p>
* Renders the response with a json object, for example,
* <pre>
* {
* "sc": boolean,
* "comments": [{
* "oId": "",
* "commentName": "",
* "thumbnailUrl": "",
* "commentURL": "",
* "commentContent": "",
* "commentTime": long,
* "commentSharpURL": "",
* "isReply": boolean
* }, ....]
* }
* </pre>
* </p>
*
* @param context the specified request context
*/
public void getPageComments(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
context.setRenderer(renderer);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
try {
final String pageId = context.pathVar("id");
final List<JSONObject> comments = commentQueryService.getComments(pageId);
ret.put(Comment.COMMENTS, comments);
ret.put(Keys.STATUS_CODE, true);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e);
final JSONObject jsonObject = new JSONObject().put(Keys.STATUS_CODE, false);
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
}
}
}
......@@ -18,12 +18,10 @@
package org.b3log.solo.service;
import org.b3log.latke.Keys;
import org.b3log.latke.util.Requests;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Page;
import org.b3log.solo.util.Solos;
import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.Test;
......@@ -34,7 +32,7 @@ import java.util.List;
* {@link CommentMgmtService} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, Sep 16, 2018
* @version 1.0.0.4, Apr 18, 2019
*/
@Test(suiteName = "service")
public class CommentMgmtServiceTestCase extends AbstractTestCase {
......@@ -91,59 +89,6 @@ public class CommentMgmtServiceTestCase extends AbstractTestCase {
Assert.assertEquals(result.getJSONArray(Comment.COMMENTS).length(), 2);
}
/**
* Add Page Comment.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "addArticleComment")
public void addPageComment() throws Exception {
addPage();
final PageQueryService pageQueryService = getPageQueryService();
final JSONObject paginationRequest = Solos.buildPaginationRequest("1/10/20");
JSONObject result = pageQueryService.getPages(paginationRequest);
Assert.assertNotNull(result);
Assert.assertEquals(result.getJSONArray(Page.PAGES).length(), 1);
final JSONArray pages = result.getJSONArray(Page.PAGES);
final CommentQueryService commentQueryService = getCommentQueryService();
result = commentQueryService.getComments(paginationRequest);
Assert.assertNotNull(result);
Assert.assertEquals(result.getJSONArray(Comment.COMMENTS).length(),
2); // 2 article comments
final CommentMgmtService commentMgmtService = getCommentMgmtService();
final JSONObject requestJSONObject = new JSONObject();
final String pageId = pages.getJSONObject(0).getString(Keys.OBJECT_ID);
requestJSONObject.put(Keys.OBJECT_ID, pageId);
requestJSONObject.put(Comment.COMMENT_NAME, "Solo");
requestJSONObject.put(Comment.COMMENT_URL, "comment URL");
requestJSONObject.put(Comment.COMMENT_CONTENT, "comment content");
final JSONObject addResult = commentMgmtService.addPageComment(requestJSONObject);
Assert.assertNotNull(addResult);
Assert.assertNotNull(addResult.getString(Keys.OBJECT_ID));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_T_DATE));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_THUMBNAIL_URL));
Assert.assertNotNull(addResult.getString(Comment.COMMENT_SHARP_URL));
result = commentQueryService.getComments(paginationRequest);
Assert.assertNotNull(result);
Assert.assertEquals(result.getJSONArray(Comment.COMMENTS).length(),
3); // 2 article comments + 1 page comment
final List<JSONObject> pageComments = commentQueryService.getComments(pageId);
Assert.assertNotNull(pageComments);
Assert.assertEquals(pageComments.size(), 1);
}
/**
* Adds a page.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment