Skip to content

Commit

Permalink
♻️ 重构请求路由 #5
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Feb 11, 2020
1 parent a816f2a commit 44a08ab
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/main/java/org/b3log/symphony/processor/VoteProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
package org.b3log.symphony.processor;

import org.b3log.latke.Keys;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.Before;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.User;
import org.b3log.latke.service.LangPropsService;
import org.b3log.symphony.model.*;
Expand All @@ -47,10 +46,10 @@
* </ul>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.0.6, Jun 27, 2018
* @version 2.0.0.0, Feb 11, 2020
* @since 1.3.0
*/
@RequestProcessor
@Singleton
public class VoteProcessor {

/**
Expand Down Expand Up @@ -94,6 +93,21 @@ public class VoteProcessor {
@Inject
private NotificationMgmtService notificationMgmtService;

/**
* Register request handlers.
*/
public static void register() {
final BeanManager beanManager = BeanManager.getInstance();
final LoginCheckMidware loginCheck = beanManager.getReference(LoginCheckMidware.class);
final PermissionMidware permissionMidware = beanManager.getReference(PermissionMidware.class);

final VoteProcessor voteProcessor = beanManager.getReference(VoteProcessor.class);
Dispatcher.post("/vote/up/comment", voteProcessor::voteUpComment, loginCheck::handle, permissionMidware::check);
Dispatcher.post("/vote/down/comment", voteProcessor::voteDownComment, loginCheck::handle, permissionMidware::check);
Dispatcher.post("/vote/up/article", voteProcessor::voteUpArticle, loginCheck::handle, permissionMidware::check);
Dispatcher.post("/vote/down/article", voteProcessor::voteDownArticle, loginCheck::handle, permissionMidware::check);
}

/**
* Votes up a comment.
* <p>
Expand All @@ -107,8 +121,6 @@ public class VoteProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/vote/up/comment", method = HttpMethod.POST)
@Before({LoginCheckMidware.class, PermissionMidware.class})
public void voteUpComment(final RequestContext context) {
context.renderJSON();

Expand Down Expand Up @@ -161,8 +173,6 @@ public void voteUpComment(final RequestContext context) {
*
* @param context the specified context
*/
@RequestProcessing(value = "/vote/down/comment", method = HttpMethod.POST)
@Before({LoginCheckMidware.class, PermissionMidware.class})
public void voteDownComment(final RequestContext context) {
context.renderJSON();

Expand Down Expand Up @@ -217,8 +227,6 @@ public void voteDownComment(final RequestContext context) {
*
* @param context the specified context
*/
@RequestProcessing(value = "/vote/up/article", method = HttpMethod.POST)
@Before({LoginCheckMidware.class, PermissionMidware.class})
public void voteUpArticle(final RequestContext context) {
context.renderJSON();

Expand Down Expand Up @@ -272,8 +280,6 @@ public void voteUpArticle(final RequestContext context) {
*
* @param context the specified context
*/
@RequestProcessing(value = "/vote/down/article", method = HttpMethod.POST)
@Before({LoginCheckMidware.class, PermissionMidware.class})
public void voteDownArticle(final RequestContext context) {
context.renderJSON();

Expand Down

0 comments on commit 44a08ab

Please sign in to comment.