Skip to content

Commit

Permalink
♻️ sc 调整为 code #30
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jun 20, 2020
1 parent 738754b commit 724bb44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/b3log/symphony/processor/TagProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.b3log.symphony.processor.middleware.LoginCheckMidware;
import org.b3log.symphony.service.*;
import org.b3log.symphony.util.Sessions;
import org.b3log.symphony.util.StatusCodes;
import org.b3log.symphony.util.Symphonys;
import org.json.JSONObject;

Expand Down Expand Up @@ -113,7 +114,7 @@ public void queryTags(final RequestContext context) {
return;
}

context.renderJSON().renderTrueResult();
context.renderJSON(StatusCodes.SUCC);

final String titlePrefix = context.param("title");

Expand Down
28 changes: 13 additions & 15 deletions src/main/java/org/b3log/symphony/processor/VoteProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.b3log.symphony.processor.middleware.PermissionMidware;
import org.b3log.symphony.service.*;
import org.b3log.symphony.util.Sessions;
import org.b3log.symphony.util.StatusCodes;
import org.json.JSONObject;

import java.util.HashSet;
Expand Down Expand Up @@ -122,7 +123,7 @@ public static void register() {
* @param context the specified context
*/
public void voteUpComment(final RequestContext context) {
context.renderJSON();
context.renderJSON(StatusCodes.ERR);

final JSONObject requestJSONObject = context.requestJSON();
final String dataId = requestJSONObject.optString(Common.DATA_ID);
Expand All @@ -132,7 +133,7 @@ public void voteUpComment(final RequestContext context) {

if (!Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE))
&& voteQueryService.isOwn(userId, dataId, Vote.DATA_TYPE_C_COMMENT)) {
context.renderFalseResult().renderMsg(langPropsService.get("cantVoteSelfLabel"));
context.renderMsg(langPropsService.get("cantVoteSelfLabel"));
return;
}

Expand All @@ -156,7 +157,7 @@ public void voteUpComment(final RequestContext context) {
VOTES.add(userId + dataId);
}

context.renderTrueResult().renderJSONValue(Vote.TYPE, vote);
context.renderJSON(StatusCodes.SUCC).renderJSONValue(Vote.TYPE, vote);
}

/**
Expand All @@ -173,9 +174,8 @@ public void voteUpComment(final RequestContext context) {
* @param context the specified context
*/
public void voteDownComment(final RequestContext context) {
context.renderJSON();
context.renderJSON(StatusCodes.ERR);

final Request request = context.getRequest();
final JSONObject requestJSONObject = context.requestJSON();
final String dataId = requestJSONObject.optString(Common.DATA_ID);

Expand All @@ -184,7 +184,7 @@ public void voteDownComment(final RequestContext context) {

if (!Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE))
&& voteQueryService.isOwn(userId, dataId, Vote.DATA_TYPE_C_COMMENT)) {
context.renderFalseResult().renderMsg(langPropsService.get("cantVoteSelfLabel"));
context.renderMsg(langPropsService.get("cantVoteSelfLabel"));
return;
}

Expand All @@ -209,7 +209,7 @@ public void voteDownComment(final RequestContext context) {
// VOTES.add(userId + dataId);
}

context.renderTrueResult().renderJSONValue(Vote.TYPE, vote);
context.renderJSON(StatusCodes.SUCC).renderJSONValue(Vote.TYPE, vote);
}

/**
Expand All @@ -226,9 +226,8 @@ public void voteDownComment(final RequestContext context) {
* @param context the specified context
*/
public void voteUpArticle(final RequestContext context) {
context.renderJSON();
context.renderJSON(StatusCodes.ERR);

final Request request = context.getRequest();
final JSONObject requestJSONObject = context.requestJSON();
final String dataId = requestJSONObject.optString(Common.DATA_ID);

Expand All @@ -237,7 +236,7 @@ public void voteUpArticle(final RequestContext context) {

if (!Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE))
&& voteQueryService.isOwn(userId, dataId, Vote.DATA_TYPE_C_ARTICLE)) {
context.renderFalseResult().renderMsg(langPropsService.get("cantVoteSelfLabel"));
context.renderMsg(langPropsService.get("cantVoteSelfLabel"));
return;
}

Expand All @@ -261,7 +260,7 @@ public void voteUpArticle(final RequestContext context) {
VOTES.add(userId + dataId);
}

context.renderTrueResult().renderJSONValue(Vote.TYPE, vote);
context.renderJSON(StatusCodes.SUCC).renderJSONValue(Vote.TYPE, vote);
}

/**
Expand All @@ -278,9 +277,8 @@ public void voteUpArticle(final RequestContext context) {
* @param context the specified context
*/
public void voteDownArticle(final RequestContext context) {
context.renderJSON();
context.renderJSON(StatusCodes.ERR);

final Request request = context.getRequest();
final JSONObject requestJSONObject = context.requestJSON();
final String dataId = requestJSONObject.optString(Common.DATA_ID);

Expand All @@ -289,7 +287,7 @@ public void voteDownArticle(final RequestContext context) {

if (!Role.ROLE_ID_C_ADMIN.equals(currentUser.optString(User.USER_ROLE))
&& voteQueryService.isOwn(userId, dataId, Vote.DATA_TYPE_C_ARTICLE)) {
context.renderFalseResult().renderMsg(langPropsService.get("cantVoteSelfLabel"));
context.renderMsg(langPropsService.get("cantVoteSelfLabel"));
return;
}

Expand All @@ -314,6 +312,6 @@ public void voteDownArticle(final RequestContext context) {
// VOTES.add(userId + dataId);
}

context.renderTrueResult().renderJSONValue(Vote.TYPE, vote);
context.renderJSON(StatusCodes.SUCC).renderJSONValue(Vote.TYPE, vote);
}
}

0 comments on commit 724bb44

Please sign in to comment.