Search in sources :

Example 6 with Route

use of com.blade.mvc.annotation.Route in project tale by otale.

the class CommentController method delete.

@Route(value = "status", method = HttpMethod.POST)
@JSON
public RestResponse delete(@QueryParam Integer coid, @QueryParam String status) {
    try {
        Comments comments = new Comments();
        comments.setCoid(coid);
        comments.setStatus(status);
        commentsService.update(comments);
        siteService.cleanCache(Types.C_STATISTICS);
    } catch (Exception e) {
        String msg = "操作失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Comments(com.tale.model.Comments) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 7 with Route

use of com.blade.mvc.annotation.Route in project tale by otale.

the class IndexController method upPwd.

/**
     * 修改密码
     */
@Route(value = "password", method = HttpMethod.POST)
@JSON
public RestResponse upPwd(@QueryParam String old_password, @QueryParam String password, Request request) {
    Users users = this.user();
    if (StringKit.isBlank(old_password) || StringKit.isBlank(password)) {
        return RestResponse.fail("请确认信息输入完整");
    }
    if (!users.getPassword().equals(Tools.md5(users.getUsername() + old_password))) {
        return RestResponse.fail("旧密码错误");
    }
    if (password.length() < 6 || password.length() > 14) {
        return RestResponse.fail("请输入6-14位密码");
    }
    try {
        Users temp = new Users();
        temp.setUid(users.getUid());
        String pwd = Tools.md5(users.getUsername() + password);
        temp.setPassword(pwd);
        usersService.update(temp);
        logService.save(LogActions.UP_PWD, null, request.address(), this.getUid());
        return RestResponse.ok();
    } catch (Exception e) {
        String msg = "密码修改失败";
        if (e instanceof TipException) {
            msg = e.getMessage();
        } else {
            LOGGER.error(msg, e);
        }
        return RestResponse.fail(msg);
    }
}
Also used : Users(com.tale.model.Users) TipException(com.tale.exception.TipException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Example 8 with Route

use of com.blade.mvc.annotation.Route in project tale by otale.

the class IndexController method index.

/**
     * 仪表盘
     */
@Route(value = { "/", "index" }, method = HttpMethod.GET)
public String index(Request request) {
    List<Comments> comments = siteService.recentComments(5);
    List<Contents> contents = siteService.getContens(Types.RECENT_ARTICLE, 5);
    Statistics statistics = siteService.getStatistics();
    // 取最新的20条日志
    List<Logs> logs = logService.getLogs(1, 20);
    request.attribute("comments", comments);
    request.attribute("articles", contents);
    request.attribute("statistics", statistics);
    request.attribute("logs", logs);
    return "admin/index";
}
Also used : Contents(com.tale.model.Contents) Comments(com.tale.model.Comments) Logs(com.tale.model.Logs) Statistics(com.tale.dto.Statistics) Route(com.blade.mvc.annotation.Route)

Example 9 with Route

use of com.blade.mvc.annotation.Route in project blade by biezhi.

the class RouteBuilder method addRouter.

/**
     * Parse all routing in a controller
     *
     * @param router resolve the routing class
     */
public void addRouter(final Class<?> router) {
    Method[] methods = router.getMethods();
    if (null == methods || methods.length == 0) {
        return;
    }
    String nameSpace = null, suffix = null;
    if (null != router.getAnnotation(Controller.class)) {
        nameSpace = router.getAnnotation(Controller.class).value();
        suffix = router.getAnnotation(Controller.class).suffix();
    }
    if (null != router.getAnnotation(RestController.class)) {
        nameSpace = router.getAnnotation(RestController.class).value();
        suffix = router.getAnnotation(RestController.class).suffix();
    }
    if (null == nameSpace) {
        LOGGER.warn("Route [{}] not controller annotation", router.getName());
        return;
    }
    for (Method method : methods) {
        Route mapping = method.getAnnotation(Route.class);
        //route method
        if (null != mapping) {
            // build multiple route
            HttpMethod methodType = mapping.method();
            String[] paths = mapping.values();
            if (mapping.value().length > 1 || !mapping.value()[0].equals("/")) {
                paths = mapping.value();
            }
            if (paths.length > 0) {
                for (String path : paths) {
                    String pathV = getRoutePath(path, nameSpace, suffix);
                    this.buildRoute(router, method, pathV, methodType);
                }
            }
        }
    }
}
Also used : RestController(com.blade.mvc.annotation.RestController) HttpMethod(com.blade.mvc.http.HttpMethod) Method(java.lang.reflect.Method) RestController(com.blade.mvc.annotation.RestController) Controller(com.blade.mvc.annotation.Controller) Route(com.blade.mvc.annotation.Route) HttpMethod(com.blade.mvc.http.HttpMethod)

Example 10 with Route

use of com.blade.mvc.annotation.Route in project tale by otale.

the class AttachController method delete.

@Route(value = "delete")
@JSON
public RestResponse delete(@QueryParam Integer id, Request request) {
    try {
        Attach attach = attachService.byId(id);
        if (null == attach)
            return RestResponse.fail("不存在该附件");
        attachService.delete(id);
        siteService.cleanCache(Types.C_STATISTICS);
        String upDir = CLASSPATH.substring(0, CLASSPATH.length() - 1);
        FileKit.delete(upDir + attach.getFkey());
        logService.save(LogActions.DEL_ATTACH, attach.getFkey(), request.address(), this.getUid());
    } catch (Exception e) {
        String msg = "附件删除失败";
        if (e instanceof TipException)
            msg = e.getMessage();
        else
            LOGGER.error(msg, e);
        return RestResponse.fail(msg);
    }
    return RestResponse.ok();
}
Also used : Attach(com.tale.model.Attach) TipException(com.tale.exception.TipException) IOException(java.io.IOException) TipException(com.tale.exception.TipException) JSON(com.blade.mvc.annotation.JSON) Route(com.blade.mvc.annotation.Route)

Aggregations

Route (com.blade.mvc.annotation.Route)18 TipException (com.tale.exception.TipException)14 JSON (com.blade.mvc.annotation.JSON)13 Users (com.tale.model.Users)7 Comments (com.tale.model.Comments)5 Config (com.blade.kit.base.Config)3 File (java.io.File)3 Attach (com.tale.model.Attach)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Take (com.blade.jdbc.core.Take)1 Controller (com.blade.mvc.annotation.Controller)1 RestController (com.blade.mvc.annotation.RestController)1 HttpMethod (com.blade.mvc.http.HttpMethod)1 FileItem (com.blade.mvc.multipart.FileItem)1 RestResponse (com.blade.mvc.view.RestResponse)1 BackResponse (com.tale.dto.BackResponse)1 Statistics (com.tale.dto.Statistics)1 ThemeDto (com.tale.dto.ThemeDto)1 Contents (com.tale.model.Contents)1