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 752dd1c commit 3fa7e70
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/main/java/org/b3log/symphony/processor/TopProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@
*/
package org.b3log.symphony.processor;

import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.After;
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.http.renderer.AbstractFreeMarkerRenderer;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.symphony.model.Common;
import org.b3log.symphony.processor.middleware.AnonymousViewCheckMidware;
import org.b3log.symphony.processor.middleware.stopwatch.StopwatchEndAdvice;
import org.b3log.symphony.processor.middleware.stopwatch.StopwatchStartAdvice;
import org.b3log.symphony.processor.middleware.PermissionMidware;
import org.b3log.symphony.service.*;
import org.b3log.symphony.util.Symphonys;
import org.json.JSONObject;
Expand All @@ -47,10 +44,10 @@
* </ul>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.4.0.1, Jan 5, 2019
* @version 2.0.0.0, Feb 11, 2020
* @since 1.3.0
*/
@RequestProcessor
@Singleton
public class TopProcessor {

/**
Expand Down Expand Up @@ -83,14 +80,27 @@ public class TopProcessor {
@Inject
private LinkQueryService linkQueryService;

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

final TopProcessor topProcessor = beanManager.getReference(TopProcessor.class);
Dispatcher.get("/top", topProcessor::showTop, anonymousViewCheckMidware::handle, permissionMidware::grant);
Dispatcher.get("/top/link", topProcessor::showLink, anonymousViewCheckMidware::handle, permissionMidware::grant);
Dispatcher.get("/top/balance", topProcessor::showBalance, anonymousViewCheckMidware::handle, permissionMidware::grant);
Dispatcher.get("/top/consumption", topProcessor::showConsumption, anonymousViewCheckMidware::handle, permissionMidware::grant);
Dispatcher.get("/top/checkin", topProcessor::showCheckin, anonymousViewCheckMidware::handle, permissionMidware::grant);
}

/**
* Shows top.
*
* @param context the specified context
*/
@RequestProcessing(value = "/top", method = HttpMethod.GET)
@Before({StopwatchStartAdvice.class, AnonymousViewCheckMidware.class})
@After({PermissionGrant.class, StopwatchEndAdvice.class})
public void showTop(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "top/index.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
Expand All @@ -108,9 +118,6 @@ public void showTop(final RequestContext context) {
*
* @param context the specified context
*/
@RequestProcessing(value = "/top/link", method = HttpMethod.GET)
@Before({StopwatchStartAdvice.class, AnonymousViewCheckMidware.class})
@After({PermissionGrant.class, StopwatchEndAdvice.class})
public void showLink(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "top/link.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
Expand All @@ -129,9 +136,6 @@ public void showLink(final RequestContext context) {
*
* @param context the specified context
*/
@RequestProcessing(value = "/top/balance", method = HttpMethod.GET)
@Before({StopwatchStartAdvice.class, AnonymousViewCheckMidware.class})
@After({PermissionGrant.class, StopwatchEndAdvice.class})
public void showBalance(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "top/balance.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
Expand All @@ -150,9 +154,6 @@ public void showBalance(final RequestContext context) {
*
* @param context the specified context
*/
@RequestProcessing(value = "/top/consumption", method = HttpMethod.GET)
@Before({StopwatchStartAdvice.class, AnonymousViewCheckMidware.class})
@After({PermissionGrant.class, StopwatchEndAdvice.class})
public void showConsumption(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "top/consumption.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
Expand All @@ -171,9 +172,6 @@ public void showConsumption(final RequestContext context) {
*
* @param context the specified context
*/
@RequestProcessing(value = "/top/checkin", method = HttpMethod.GET)
@Before({StopwatchStartAdvice.class, AnonymousViewCheckMidware.class})
@After({PermissionGrant.class, StopwatchEndAdvice.class})
public void showCheckin(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "top/checkin.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
Expand Down

0 comments on commit 3fa7e70

Please sign in to comment.