接口路径变更

This commit is contained in:
x ronger 2019-11-18 19:39:37 +08:00
parent f684510fcb
commit 6b5b42c419
2 changed files with 36 additions and 32 deletions

View File

@ -1,20 +1,15 @@
package com.rymcu.vertical.web.api.article; package com.rymcu.vertical.web.api.article;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rymcu.vertical.core.mapper.Mapper;
import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResult;
import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.core.result.GlobalResultGenerator;
import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.entity.Article;
import com.rymcu.vertical.jwt.def.JwtConstants;
import com.rymcu.vertical.service.ArticleService; import com.rymcu.vertical.service.ArticleService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@ -24,21 +19,6 @@ public class ArticleController {
@Resource @Resource
private ArticleService articleService; private ArticleService articleService;
@GetMapping("/articles")
public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page,@RequestParam(defaultValue = "10") Integer rows,@RequestParam(defaultValue = "") String searchText,@RequestParam(defaultValue = "") String tag){
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.articles(searchText,tag);
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap();
map.put("articles", pageInfo.getList());
Map pagination = new HashMap();
pagination.put("paginationPageCount",pageInfo.getPages());
pagination.put("paginationPageNums",pageInfo.getNavigatepageNums());
pagination.put("currentPage",pageInfo.getPageNum());
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
}
@PostMapping("/post") @PostMapping("/post")
public GlobalResult postArticle(@RequestParam(name = "idArticle",defaultValue = "0") Integer idArticle,@RequestParam(name = "articleTitle",defaultValue = "") String articleTitle, public GlobalResult postArticle(@RequestParam(name = "idArticle",defaultValue = "0") Integer idArticle,@RequestParam(name = "articleTitle",defaultValue = "") String articleTitle,
@RequestParam(name = "articleContent",defaultValue = "") String articleContent,@RequestParam(name = "articleContentHtml",defaultValue = "") String articleContentHtml, @RequestParam(name = "articleContent",defaultValue = "") String articleContent,@RequestParam(name = "articleContentHtml",defaultValue = "") String articleContentHtml,
@ -47,12 +27,4 @@ public class ArticleController {
return GlobalResultGenerator.genSuccessResult(map); return GlobalResultGenerator.genSuccessResult(map);
} }
@GetMapping("/detail/{id}")
public GlobalResult detail(@PathVariable Integer id){
ArticleDTO articleDTO = articleService.findArticleDTOById(id);
Map map = new HashMap<>();
map.put("article", articleDTO);
return GlobalResultGenerator.genSuccessResult(map);
}
} }

View File

@ -1,10 +1,14 @@
package com.rymcu.vertical.web.api.common; package com.rymcu.vertical.web.api.common;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rymcu.vertical.core.exception.ServiceException; import com.rymcu.vertical.core.exception.ServiceException;
import com.rymcu.vertical.core.result.GlobalResult; import com.rymcu.vertical.core.result.GlobalResult;
import com.rymcu.vertical.core.result.GlobalResultGenerator; import com.rymcu.vertical.core.result.GlobalResultGenerator;
import com.rymcu.vertical.core.result.GlobalResultMessage; import com.rymcu.vertical.core.result.GlobalResultMessage;
import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.entity.User; import com.rymcu.vertical.entity.User;
import com.rymcu.vertical.service.ArticleService;
import com.rymcu.vertical.service.JavaMailService; import com.rymcu.vertical.service.JavaMailService;
import com.rymcu.vertical.service.UserService; import com.rymcu.vertical.service.UserService;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -12,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@ -22,6 +27,8 @@ public class CommonApiController {
private JavaMailService javaMailService; private JavaMailService javaMailService;
@Resource @Resource
private UserService userService; private UserService userService;
@Resource
private ArticleService articleService;
@ApiOperation(value = "获取邮件验证码") @ApiOperation(value = "获取邮件验证码")
@PostMapping("/get-email-code") @PostMapping("/get-email-code")
@ -56,4 +63,29 @@ public class CommonApiController {
public GlobalResult heartbeat(){ public GlobalResult heartbeat(){
return GlobalResultGenerator.genSuccessResult("heartbeat"); return GlobalResultGenerator.genSuccessResult("heartbeat");
} }
@GetMapping("/articles")
public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page,@RequestParam(defaultValue = "10") Integer rows,@RequestParam(defaultValue = "") String searchText,@RequestParam(defaultValue = "") String tag){
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.articles(searchText,tag);
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap();
map.put("articles", pageInfo.getList());
Map pagination = new HashMap();
pagination.put("paginationPageCount",pageInfo.getPages());
pagination.put("paginationPageNums",pageInfo.getNavigatepageNums());
pagination.put("currentPage",pageInfo.getPageNum());
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/articles/{id}")
public GlobalResult detail(@PathVariable Integer id){
ArticleDTO articleDTO = articleService.findArticleDTOById(id);
Map map = new HashMap<>();
map.put("article", articleDTO);
return GlobalResultGenerator.genSuccessResult(map);
}
} }