|
|
@@ -6,16 +6,13 @@ import cn.reghao.jutil.jdk.web.result.Result;
|
|
|
import cn.reghao.jutil.web.WebResult;
|
|
|
import cn.reghao.bnt.web.blog.service.ArticleQuery;
|
|
|
import cn.reghao.bnt.web.blog.model.dto.ArticleDto;
|
|
|
-import cn.reghao.bnt.web.blog.model.po.Category;
|
|
|
import cn.reghao.bnt.web.blog.model.vo.AdminArticle;
|
|
|
import cn.reghao.bnt.web.blog.model.vo.EditArticle;
|
|
|
import cn.reghao.bnt.web.blog.service.ArticleService;
|
|
|
-import cn.reghao.bnt.web.blog.service.CategoryService;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.http.MediaType;
|
|
|
-import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -31,27 +28,36 @@ import java.util.List;
|
|
|
public class AdminArticleController {
|
|
|
private final ArticleService articleService;
|
|
|
private final ArticleQuery articleQuery;
|
|
|
- private final CategoryService categoryService;
|
|
|
private final HibernateLucene hibernateLucene;
|
|
|
private int pageSize = 10;
|
|
|
|
|
|
public AdminArticleController(ArticleService articleService, ArticleQuery articleQuery,
|
|
|
- CategoryService categoryService, HibernateLucene hibernateLucene) {
|
|
|
+ HibernateLucene hibernateLucene) {
|
|
|
this.articleService = articleService;
|
|
|
this.articleQuery = articleQuery;
|
|
|
- this.categoryService = categoryService;
|
|
|
this.hibernateLucene = hibernateLucene;
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "博客文章列表页面", description = "N")
|
|
|
@GetMapping("/list")
|
|
|
public String list(@RequestParam("pn") int pageNumber,
|
|
|
- @RequestParam("categoryId") int categoryId,
|
|
|
- @RequestParam("published") int published,
|
|
|
- @RequestParam("title") String title) {
|
|
|
+ @RequestParam(value = "categoryId", required = false) Integer categoryId,
|
|
|
+ @RequestParam(value = "published", required = false) Integer published,
|
|
|
+ @RequestParam(value = "title", required = false) String title) {
|
|
|
+ if (categoryId == null) {
|
|
|
+ categoryId = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (published == null) {
|
|
|
+ published = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (title == null) {
|
|
|
+ title = "";
|
|
|
+ }
|
|
|
+
|
|
|
Page<AdminArticle> page1 = articleQuery.findAdminArticleByPage(pageSize, pageNumber, categoryId, published, title);
|
|
|
PageList<AdminArticle> pageList = getPageList(page1);
|
|
|
- List<Category> list = categoryService.findAllCategory();
|
|
|
return WebResult.success(pageList);
|
|
|
}
|
|
|
|
|
|
@@ -63,42 +69,15 @@ public class AdminArticleController {
|
|
|
return PageList.pageList(pageNumber, pageSize, (int) total, list);
|
|
|
}
|
|
|
|
|
|
- @Operation(summary = "新建/编辑文章页面", description = "N")
|
|
|
+ @Operation(summary = "编辑文章", description = "N")
|
|
|
@GetMapping("/edit")
|
|
|
- public String edit(String editor, String articleId, ModelMap model) {
|
|
|
- if (editor == null) {
|
|
|
- editor = "markdown";
|
|
|
- }
|
|
|
- List<Category> list = categoryService.findAllCategory();
|
|
|
-
|
|
|
- String pageTitle = "新建文章";
|
|
|
- String submitTitle = "发布文章";
|
|
|
- boolean newArticle = true;
|
|
|
- EditArticle editArticle = null;
|
|
|
- if (articleId != null) {
|
|
|
- pageTitle = "编辑文章";
|
|
|
- submitTitle = "更新文章";
|
|
|
- newArticle = false;
|
|
|
- editArticle = articleQuery.getEditArticle(articleId);
|
|
|
- editor = editArticle.getEditor();
|
|
|
- }
|
|
|
-
|
|
|
- model.put("pageTitle", pageTitle);
|
|
|
- model.put("submitTitle", submitTitle);
|
|
|
- model.put("newArticle", newArticle);
|
|
|
- if (newArticle) {
|
|
|
- model.put("editors", List.of("markdown", "tinymce"));
|
|
|
- } else {
|
|
|
- model.put("view", editArticle);
|
|
|
- }
|
|
|
- model.put("editor", editor);
|
|
|
- model.put("categories", list);
|
|
|
- return "/admin/blog/post/edit";
|
|
|
+ public String edit(@RequestParam("articleId") String articleId) {
|
|
|
+ EditArticle editArticle = articleQuery.getEditArticle(articleId);
|
|
|
+ return WebResult.success(editArticle);
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "新增/更新文章接口", description = "N")
|
|
|
@PostMapping(value = "/edit", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- @ResponseBody
|
|
|
public String editArticle(@Validated ArticleDto articleDto) {
|
|
|
String articleId = articleDto.getArticleId();
|
|
|
Result result;
|
|
|
@@ -113,19 +92,13 @@ public class AdminArticleController {
|
|
|
|
|
|
@Operation(summary = "删除文章", description = "N")
|
|
|
@PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- @ResponseBody
|
|
|
- public String delete(@RequestParam("articleId") List<String> articleIds) {
|
|
|
- if (articleIds.size() != 1) {
|
|
|
- return WebResult.failWithMsg("只能删除一篇文章");
|
|
|
- }
|
|
|
-
|
|
|
- articleService.deleteArticle(articleIds.get(0));
|
|
|
+ public String delete(@RequestParam("articleId") String articleId) {
|
|
|
+ articleService.deleteArticle(articleId);
|
|
|
return WebResult.success();
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "重置文章索引", description = "N")
|
|
|
@PostMapping(value = "/reset_indexes", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- @ResponseBody
|
|
|
public String resetIndexes() {
|
|
|
hibernateLucene.resetIndexes();
|
|
|
return WebResult.success();
|