|
|
@@ -1,9 +1,9 @@
|
|
|
package cn.reghao.bnt.web.blog.controller;
|
|
|
|
|
|
import cn.reghao.bnt.web.blog.model.dto.QuestionUpdateDto;
|
|
|
+import cn.reghao.jutil.jdk.web.db.PageList;
|
|
|
import cn.reghao.jutil.jdk.web.result.Result;
|
|
|
import cn.reghao.jutil.jdk.web.result.WebResult;
|
|
|
-import cn.reghao.jutil.web.ServletUtil;
|
|
|
import cn.reghao.bnt.web.blog.model.dto.QuestionDto;
|
|
|
import cn.reghao.bnt.web.blog.model.po.Category;
|
|
|
import cn.reghao.bnt.web.blog.model.po.Question;
|
|
|
@@ -14,13 +14,10 @@ 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.stereotype.Controller;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.ServletRequestUtils;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
-import jakarta.servlet.http.HttpServletRequest;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
@@ -28,11 +25,12 @@ import java.util.List;
|
|
|
* @date 2023-04-17 10:15:39
|
|
|
*/
|
|
|
@Tag(name = "面试题接口")
|
|
|
-@Controller
|
|
|
-@RequestMapping("/bg/blog/interview")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/blog/v2/question")
|
|
|
public class AdminQuestionController {
|
|
|
private final CategoryService categoryService;
|
|
|
private final QuestionService questionService;
|
|
|
+ private int pageSize = 100;
|
|
|
|
|
|
public AdminQuestionController(CategoryService categoryService, QuestionService questionService) {
|
|
|
this.categoryService = categoryService;
|
|
|
@@ -40,33 +38,25 @@ public class AdminQuestionController {
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "面试题列表页面", description = "N")
|
|
|
- @GetMapping("/question/list")
|
|
|
- public String list(ModelMap model, HttpServletRequest request) {
|
|
|
- int id = ServletRequestUtils.getIntParameter(request, "id", 0);
|
|
|
- int pageNumber = Integer.parseInt(ServletUtil.getRequestParam("pageNo", "1"));
|
|
|
- int categoryId1 = Integer.parseInt(ServletUtil.getRequestParam("categoryId", "0"));
|
|
|
- String title1 = ServletUtil.getRequestParam("title", "");
|
|
|
- int pageSize = 100;
|
|
|
- Page<QuestionView> page0 = questionService.findQuestionByPage(pageSize, pageNumber, categoryId1);
|
|
|
-
|
|
|
- String queryParams = "";
|
|
|
- if (categoryId1 != 0) {
|
|
|
- queryParams += "?categoryId=" + categoryId1;
|
|
|
- }
|
|
|
-
|
|
|
- model.put("id", id);
|
|
|
- model.put("title", title1);
|
|
|
- model.put("categoryId", categoryId1);
|
|
|
- model.addAttribute("query", queryParams);
|
|
|
- model.put("page", page0);
|
|
|
+ @GetMapping("/list")
|
|
|
+ public String list(@RequestParam("pn") int pageNumber,
|
|
|
+ @RequestParam("categoryId") int categoryId,
|
|
|
+ @RequestParam("title") String title) {
|
|
|
+ Page<QuestionView> page0 = questionService.findQuestionByPage(pageSize, pageNumber, categoryId);
|
|
|
+ PageList<QuestionView> pageList = getPageList(page0);
|
|
|
+ return WebResult.success(pageList);
|
|
|
+ }
|
|
|
|
|
|
- List<Category> list = questionService.getCategories();
|
|
|
- model.put("categories", list);
|
|
|
- return "/admin/blog/question/list";
|
|
|
+ private PageList<QuestionView> getPageList(Page<QuestionView> page) {
|
|
|
+ int pageNumber = page.getNumber() + 1;
|
|
|
+ int pageSize = page.getSize();
|
|
|
+ long total = page.getTotalElements();
|
|
|
+ List<QuestionView> list = page.getContent();
|
|
|
+ return PageList.pageList(pageNumber, pageSize, (int) total, list);
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "添加面试题页面", description = "N")
|
|
|
- @GetMapping("/question/new")
|
|
|
+ @GetMapping("/new")
|
|
|
public String addArticlePage(String editor, ModelMap model) {
|
|
|
if (editor == null) {
|
|
|
editor = "markdown";
|
|
|
@@ -76,11 +66,11 @@ public class AdminQuestionController {
|
|
|
model.put("editor", editor);
|
|
|
model.put("editors", List.of("markdown", "tinymce"));
|
|
|
model.put("categories", list);
|
|
|
- return "/admin/blog/question/new";
|
|
|
+ return "/admin/blog/new";
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "添加面试题接口", description = "N")
|
|
|
- @PostMapping(value = "/question/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ResponseBody
|
|
|
public String addArticle(@Validated QuestionDto questionDto) {
|
|
|
Result result = questionService.addQuestion(questionDto);
|
|
|
@@ -88,23 +78,23 @@ public class AdminQuestionController {
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "修改面试题页面", description = "N")
|
|
|
- @GetMapping("/question/edit")
|
|
|
+ @GetMapping("/edit")
|
|
|
public String edit(String questionId, ModelMap model) {
|
|
|
Question question = questionService.findByQuestionId(questionId);
|
|
|
model.put("editor", "markdown");
|
|
|
model.put("view", question);
|
|
|
- return "/admin/blog/question/edit";
|
|
|
+ return "/admin/blog/edit";
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "修改面试题接口", description = "N")
|
|
|
- @PostMapping(value = "/question/update")
|
|
|
+ @PostMapping(value = "/update")
|
|
|
public String updateArticle(@Validated QuestionUpdateDto questionUpdateDto) {
|
|
|
questionService.updateQuestion(questionUpdateDto);
|
|
|
- return "redirect:/bg/blog/interview/question/list";
|
|
|
+ return "redirect:/bg/blog/interview/list";
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "面试题加权重接口", description = "N")
|
|
|
- @PostMapping(value = "/question/weight/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PostMapping(value = "/weight/add", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ResponseBody
|
|
|
public String addWeight(String questionId) {
|
|
|
questionService.addWeight(questionId);
|
|
|
@@ -112,7 +102,7 @@ public class AdminQuestionController {
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "面试题减权重接口", description = "N")
|
|
|
- @PostMapping(value = "/question/weight/minus", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PostMapping(value = "/weight/minus", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ResponseBody
|
|
|
public String minusWeight(String questionId) {
|
|
|
questionService.minusWeight(questionId);
|
|
|
@@ -120,7 +110,7 @@ public class AdminQuestionController {
|
|
|
}
|
|
|
|
|
|
@Operation(summary = "删除面试题接口", description = "N")
|
|
|
- @PostMapping(value = "/question/delete", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ @PostMapping(value = "/delete", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
@ResponseBody
|
|
|
public String delete(@RequestParam("questionId") List<String> questionIds) {
|
|
|
questionService.deleteQuestions(questionIds);
|
|
|
@@ -138,6 +128,6 @@ public class AdminQuestionController {
|
|
|
}
|
|
|
|
|
|
model.put("view", questionView);
|
|
|
- return "/admin/blog/question/view";
|
|
|
+ return "/admin/blog/view";
|
|
|
}
|
|
|
}
|