You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
poetize/src/main/java/com/ld/poetry/controller/ArticleController.java

86 lines
2.3 KiB

package com.ld.poetry.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ld.poetry.config.LoginCheck;
import com.ld.poetry.config.PoetryResult;
import com.ld.poetry.service.ArticleService;
import com.ld.poetry.utils.CommonConst;
import com.ld.poetry.utils.PoetryCache;
import com.ld.poetry.utils.PoetryUtil;
import com.ld.poetry.vo.ArticleVO;
import com.ld.poetry.vo.BaseRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* <p>
* 文章表 前端控制器
* </p>
*
* @author sara
* @since 2021-08-13
*/
@RestController
@RequestMapping("/article")
public class ArticleController {
@Autowired
private ArticleService articleService;
/**
* 保存文章
*/
@LoginCheck(1)
@PostMapping("/saveArticle")
public PoetryResult saveArticle(@Validated @RequestBody ArticleVO articleVO) {
PoetryCache.remove(CommonConst.USER_ARTICLE_LIST + PoetryUtil.getUserId().toString());
PoetryCache.remove(CommonConst.ARTICLE_LIST);
return articleService.saveArticle(articleVO);
}
/**
* 删除文章
*/
@GetMapping("/deleteArticle")
@LoginCheck(1)
public PoetryResult deleteArticle(@RequestParam("id") Integer id) {
PoetryCache.remove(CommonConst.USER_ARTICLE_LIST + PoetryUtil.getUserId().toString());
PoetryCache.remove(CommonConst.ARTICLE_LIST);
return articleService.deleteArticle(id);
}
/**
* 更新文章
*/
@PostMapping("/updateArticle")
@LoginCheck(1)
public PoetryResult updateArticle(@Validated @RequestBody ArticleVO articleVO) {
PoetryCache.remove(CommonConst.ARTICLE_LIST);
return articleService.updateArticle(articleVO);
}
/**
* 查询文章List
*/
@PostMapping("/listArticle")
public PoetryResult<Page> listArticle(@RequestBody BaseRequestVO baseRequestVO) {
return articleService.listArticle(baseRequestVO);
}
/**
* 查询文章
*/
@GetMapping("/getArticleById")
public PoetryResult<ArticleVO> getArticleById(@RequestParam("id") Integer id, @RequestParam(value = "password", required = false) String password) {
return articleService.getArticleById(id, password);
}
}