Skip to content

Commit

Permalink
🐛 fixed delete page
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Oct 7, 2018
1 parent 30330d4 commit 23e8f1f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/tale/controller/ArticleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public RestResponse<?> comment(Request request, Response response,

// 设置对每个文章30秒可以评论一次
cache.hset(Types.COMMENTS_FREQUENCY, val, 1, 30);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);

return RestResponse.ok();
} catch (Exception e) {
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/com/tale/controller/admin/AdminApiController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tale.controller.admin;

import com.blade.Blade;
import com.blade.Environment;
import com.blade.ioc.annotation.Inject;
import com.blade.kit.JsonKit;
Expand Down Expand Up @@ -65,6 +64,14 @@ public RestResponse sysLogs(PageParam pageParam) {
return RestResponse.ok(select().from(Logs.class).order(Logs::getId, OrderBy.DESC).page(pageParam.getPage(), pageParam.getLimit()));
}

@SysLog("删除页面")
@PostRoute("page/delete/:cid")
public RestResponse<?> deletePage(@PathParam Integer cid) {
contentsService.delete(cid);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

@GetRoute("articles/:cid")
public RestResponse article(@PathParam String cid) {
Contents contents = contentsService.getContents(cid);
Expand Down Expand Up @@ -93,14 +100,14 @@ public RestResponse newArticle(@BodyParam Contents contents) {
contents.setCategories("默认分类");
}
Integer cid = contentsService.publish(contents);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok(cid);
}

@PostRoute("article/delete/:cid")
public RestResponse<?> deleteArticle(@PathParam Integer cid) {
contentsService.delete(cid);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand Down Expand Up @@ -142,7 +149,7 @@ public RestResponse<?> newPage(@BodyParam Contents contents) {
contents.setAllowPing(true);
contents.setAuthorId(users.getUid());
contentsService.publish(contents);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand Down Expand Up @@ -170,15 +177,15 @@ public RestResponse categories() {
@PostRoute("category/save")
public RestResponse<?> saveCategory(@BodyParam MetaParam metaParam) {
metasService.saveMeta(Types.CATEGORY, metaParam.getCname(), metaParam.getMid());
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

@SysLog("删除分类/标签")
@PostRoute("category/delete/:mid")
public RestResponse<?> deleteMeta(@PathParam Integer mid) {
metasService.delete(mid);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand All @@ -199,15 +206,15 @@ public RestResponse<?> deleteComment(@PathParam Integer coid) {
return RestResponse.fail("不存在该评论");
}
commentsService.delete(coid, comments.getCid());
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

@SysLog("修改评论状态")
@PostRoute("comment/status")
public RestResponse<?> updateStatus(@BodyParam Comments comments) {
comments.update();
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand Down Expand Up @@ -235,7 +242,7 @@ public RestResponse<?> replyComment(@BodyParam Comments comments, Request reques
comments.setStatus(TaleConst.COMMENT_APPROVED);
comments.setParent(comments.getCoid());
commentsService.saveComment(comments);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
return RestResponse.ok();
}

Expand All @@ -257,7 +264,7 @@ public RestResponse<?> deleteAttach(@PathParam Integer id) throws IOException {
return RestResponse.fail("不存在该附件");
}
String key = attach.getFkey();
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
String filePath = CLASSPATH.substring(0, CLASSPATH.length() - 1) + key;
java.nio.file.Path path = Paths.get(filePath);
log.info("Delete attach: [{}]", filePath);
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/tale/controller/admin/IndexController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.tale.utils.TaleUtils;
import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -119,7 +118,7 @@ public RestResponse<?> upload(Request request) {
attach.save();

urls.add(attach);
siteService.cleanCache(Types.C_STATISTICS);
siteService.cleanCache(Types.SYS_STATISTICS);
} else {
Attach attach = new Attach();
attach.setFname(fname);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/tale/model/dto/Types.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tale.model.dto;

/**
* Types
*
* Created by biezhi on 2017/2/21.
*/
public interface Types {
Expand All @@ -21,7 +23,7 @@ public interface Types {
String RECENT_META = "recent_meta";
String RANDOM_META = "random_meta";

String C_STATISTICS = "sys:statistics";
String SYS_STATISTICS = "sys:statistics";

String NEXT = "next";
String PREV = "prev";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tale/service/SiteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public List<Contents> getContens(String type, int limit) {
*/
public Statistics getStatistics() {

Statistics statistics = mapCache.get(Types.C_STATISTICS);
Statistics statistics = mapCache.get(Types.SYS_STATISTICS);
if (null != statistics) {
return statistics;
}
Expand All @@ -143,7 +143,7 @@ public Statistics getStatistics() {
statistics.setTags(tags);
statistics.setCategories(categories);

mapCache.set(Types.C_STATISTICS, statistics);
mapCache.set(Types.SYS_STATISTICS, statistics);
return statistics;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/templates/admin/pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ <h3 class="panel-title">页面管理</h3>
tale.alertConfirm({
title: '确定删除这个页面吗?', then: function () {
tale.post({
url: '/admin/api/page/delete',
data: {cid: cid},
url: '/admin/api/page/delete/' + cid,
success: function (result) {
if (result && result.success) {
tale.alertOk('页面删除成功');
Expand Down

0 comments on commit 23e8f1f

Please sign in to comment.