添加 javadoc

This commit is contained in:
ronger 2019-12-06 17:45:04 +08:00
parent 6b363cf37b
commit fcfb8b3cf9
32 changed files with 290 additions and 172 deletions

View File

@ -1 +1,27 @@
"# vertical"
# vertical
vertical [vərtikəl],取纵横之`纵`,寓为奔放自如、笔意纵横
## 开发计划
### 已完成
- [x] 首页
- [x] 会员登录/注册
- [x] 文章发布/编辑/详情/删除
- [x] 个人主页
- [x] 找回密码
- [x] 用户管理
- [x] 角色/权限管理 (2019/12/05 21:52 更新)
- [x] 专题管理 (2019/12/05 21:52 更新)
### 待完成
- [ ] 个人信息修改
- [ ] 标签管理
- [ ] 专题-标签管理
- [ ] 用户-标签管理
- [ ] 消息系统
- [ ] 评论系统
- [ ] SEO 优化
- [ ] 分享功能
- [ ] 数据统计
### 构想
- [ ] 专业知识题库
- [ ] 社区贡献系统
- [ ] 会员系统
- [ ] 勋章系统

View File

@ -9,6 +9,9 @@ import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
* @author ronger
*/
@Data
@Table(name = "vertical_article")
public class Article implements Serializable,Cloneable {

View File

@ -8,6 +8,9 @@ import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
/**
* @author ronger
*/
@Data
@Table(name = "vertical_article_content")
public class ArticleContent {

View File

@ -8,12 +8,15 @@ import java.io.Serializable;
/**
* 基础DO类提供toString快方法
* Created by liwei on 2015/6/16.
*
* @author liwei
* @date 2015/6/16
*/
public class BaseDO implements Serializable {
private static final long serialVersionUID = -1394589131426860408L;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}

View File

@ -9,6 +9,9 @@ import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
* @author ronger
*/
@Data
@Table(name = "vertical_tag")
public class Tag implements Serializable,Cloneable {

View File

@ -12,6 +12,9 @@ import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
* @author ronger
*/
@Table(name = "vertical_user")
@Data
public class User implements Serializable,Cloneable {

View File

@ -1,5 +1,8 @@
package com.rymcu.vertical.jwt.def;
/**
* @author ronger
*/
public class JwtConstants {
/**

View File

@ -7,10 +7,8 @@ package com.rymcu.vertical.jwt.model;
*/
public class TokenModel {
//用户id
private String username;
//随机生成的uuid
private String token;
public TokenModel(String username, String token) {

View File

@ -10,16 +10,55 @@ import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
/**
* @author ronger
*/
public interface ArticleService extends Service<Article> {
/**
* 根据检索内容/标签查询文章列表
* @param searchText
* @param tag
* @return
* */
List<ArticleDTO> findArticles(String searchText, String tag);
/**
* 查询文章详情信息
* @param id
* @param i
* @return
* */
ArticleDTO findArticleDTOById(Integer id, int i);
/**
* 查询主题下文章列表
* @param name
* @return
* */
List<ArticleDTO> findArticlesByTopicName(String name);
/**
* 查询标签下文章列表
* @param name
* @return
* */
List<ArticleDTO> findArticlesByTagName(String name);
/**
* 查询用户文章列表
* @param idUser
* @return
* */
List<ArticleDTO> findUserArticlesByIdUser(Integer idUser);
/**
* 新增/更新文章
* @param article
* @param request
* @throws UnsupportedEncodingException
* @throws BaseApiException
* @return
* */
Map postArticle(ArticleDTO article, HttpServletRequest request) throws UnsupportedEncodingException, BaseApiException;
}

View File

@ -8,7 +8,9 @@ import java.util.List;
/**
* Created by CodeGenerator on 2018/05/29.
*
* @author CodeGenerator
* @date 2018/05/29
*/
public interface PermissionService extends Service<Permission> {

View File

@ -9,15 +9,38 @@ import java.util.Map;
/**
* Created by CodeGenerator on 2018/05/29.
*
* @author CodeGenerator
* @date 2018/05/29
*/
public interface RoleService extends Service<Role> {
List<Role> selectRoleByUser(User sysUser);
/**
* 查询用户角色
* @param user
* @return
* */
List<Role> selectRoleByUser(User user);
/**
* 查询用户角色
* @param idUser
* @return
* */
List<Role> findByIdUser(Integer idUser);
/**
* 更新用户状态
* @param idRole
* @param status
* @return
* */
Map updateStatus(Integer idRole, String status);
/**
* 添加/更新角色
* @param role
* @return
* */
Map saveRole(Role role);
}

View File

@ -7,7 +7,17 @@ import com.rymcu.vertical.web.api.exception.BaseApiException;
import java.io.UnsupportedEncodingException;
/**
* @author ronger
*/
public interface TagService extends Service<Tag> {
void saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException;
/**
* 保存文章标签
* @param article
* @throws UnsupportedEncodingException
* @throws BaseApiException
* @return
* */
Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException;
}

View File

@ -26,5 +26,10 @@ public interface TopicService extends Service<Topic> {
* */
Map findTopicByTopicUri(String topicUri, Integer page, Integer rows);
/**
* 新增/更新主题信息
* @param topic 主题信息
* @return
* */
Map saveTopic(Topic topic);
}

View File

@ -9,21 +9,65 @@ import java.util.Map;
/**
* Created by CodeGenerator on 2018/05/29.
*
* @author CodeGenerator
* @date 2018/05/29
*/
public interface UserService extends Service<User> {
/**
* 通过账号查询用户信息
* @param account
* @throws TooManyResultsException
* @return User
* */
User findByAccount(String account) throws TooManyResultsException;
/**
* 注册接口
* @param email 邮箱
* @param password 密码
* @param code 验证码
* @return Map
* */
Map register(String email, String password, String code);
/**
* 登录接口
* @param account 邮箱
* @param password 密码
* @return Map
* */
Map login(String account, String password);
/**
* 通过 nickname 获取用户信息接口
* @param nickname 昵称
* @return UserDTO
* */
UserDTO findUserDTOByNickname(String nickname);
/**
* 找回密码接口
* @param code 验证码
* @param password 密码
* @return Map
* */
Map forgetPassword(String code, String password);
/**
* 更新用户角色接口
* @param idUser 用户 id
* @param idRole 角色 id
* @return Map
* */
Map updateUserRole(Integer idUser, Integer idRole);
/**
* 更新用户状态
* @param idUser 用户 id
* @param status 状态
* @return Map
* */
Map updateStatus(Integer idUser, String status);
}

View File

@ -26,6 +26,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author ronger
*/
@Service
public class ArticleServiceImpl extends AbstractService<Article> implements ArticleService {
@ -78,7 +81,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
}
@Override
@Transactional(rollbackFor = Exception.class)
@Transactional(rollbackFor = { UnsupportedEncodingException.class,BaseApiException.class })
public Map postArticle(ArticleDTO article, HttpServletRequest request) throws UnsupportedEncodingException, BaseApiException {
Map map = new HashMap(1);
if(StringUtils.isBlank(article.getArticleTitle())){

View File

@ -17,6 +17,9 @@ import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
/**
* @author ronger
*/
@Service
public class TagServiceImpl extends AbstractService<Tag> implements TagService {
@ -24,8 +27,8 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
private TagMapper tagMapper;
@Override
@Transactional
public void saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException {
@Transactional(rollbackFor = { UnsupportedEncodingException.class,BaseApiException.class })
public Integer saveTagArticle(Article article) throws UnsupportedEncodingException, BaseApiException {
User user = UserUtils.getWxCurrentUser();
String articleTags = article.getArticleTags();
if(StringUtils.isNotBlank(articleTags)){
@ -62,6 +65,8 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
tagMapper.insertUserTag(tag.getIdTag(),user.getIdUser(),1);
}
}
return 1;
}
return 0;
}
}

View File

@ -12,7 +12,8 @@ import java.security.SecureRandom;
* 支持SHA-1/MD5消息摘要的工具类.
*
* 返回ByteSource可进一步被编码为Hex, Base64或UrlSafeBase64
*
*
* @author ronger
*/
public class Digests {

View File

@ -18,6 +18,7 @@ import java.net.URLEncoder;
* 2.自制的base62 编码
* 3.Commons-Lang的xml/html escape
* 4.JDK提供的URLEncoder
* @author ronger
*/
public class Encodes {

View File

@ -1,7 +1,9 @@
package com.rymcu.vertical.util;
/**
* Created by kaenry on 2016/9/20.
*
* @author kaenry
* @date 2016/9/20
* ErrorCode
*/
public enum ErrorCode {

View File

@ -9,6 +9,7 @@ import java.io.StringWriter;
/**
* 关于异常的工具类.
* @author ronger
*/
public class Exceptions {

View File

@ -1,6 +1,8 @@
package com.rymcu.vertical.util;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
@ -12,6 +14,8 @@ import java.net.URLEncoder;
*
*/
public class FileUtils {
private static final Logger logger = LoggerFactory.getLogger(FileUtils.class);
/**
* 获取文件扩展名
*
@ -159,7 +163,7 @@ public class FileUtils {
File fileDelete = new File(strFileName);
if (!fileDelete.exists() || !fileDelete.isFile()) {
//LogUtil.info("错误: " + strFileName + "不存在!");
logger.info("错误: " + strFileName + "不存在!");
return false;
}

View File

@ -4,6 +4,9 @@ import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
import java.io.*;
/**
* @author ronger
*/
public class Html2TextUtil extends HTMLEditorKit.ParserCallback {
private static Html2TextUtil html2Text = new Html2TextUtil();

View File

@ -1,57 +0,0 @@
package com.rymcu.vertical.util;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
public class MailSSLSocketFactory extends SSLSocketFactory {
private SSLSocketFactory factory;
public MailSSLSocketFactory() throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, new TrustManager[] { new MailTrustManager() }, null);
factory = sslcontext.getSocketFactory();
}
@Override
public String[] getDefaultCipherSuites() {
return factory.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return factory.getSupportedCipherSuites();
}
@Override
public Socket createSocket(Socket socket, String s, int i, boolean b) throws IOException {
return factory.createSocket(socket, s, i, b);
}
@Override
public Socket createSocket(String s, int i) throws IOException, UnknownHostException {
return factory.createSocket(s, i);
}
@Override
public Socket createSocket(String s, int i, InetAddress inetAddress, int i1) throws IOException, UnknownHostException {
return factory.createSocket(s, i, inetAddress, i1);
}
@Override
public Socket createSocket(InetAddress inetAddress, int i) throws IOException {
return factory.createSocket(inetAddress, i);
}
@Override
public Socket createSocket(InetAddress inetAddress, int i, InetAddress inetAddress1, int i1) throws IOException {
return factory.createSocket(inetAddress, i, inetAddress1, i1);
}
}

View File

@ -1,22 +0,0 @@
package com.rymcu.vertical.util;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class MailTrustManager implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}

View File

@ -19,7 +19,8 @@ import java.util.Date;
/**
* 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候取出ApplicaitonContext.
*
*
* @author ronger
*/
@Service
@Lazy(false)

View File

@ -1,5 +1,7 @@
package com.rymcu.vertical.util;
import com.github.pagehelper.PageInfo;
import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.InvalidSessionException;
@ -9,7 +11,12 @@ import org.springframework.core.env.Environment;
import java.time.*;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* @author ronger
*/
public class Utils {
public static final String HASH_ALGORITHM = "SHA-1";
public static final int HASH_INTERATIONS = 1024;
@ -53,7 +60,7 @@ public class Utils {
if (session != null){
return session;
}
// subject.logout();
subject.logout();
}catch (InvalidSessionException e){
}
@ -110,6 +117,14 @@ public class Utils {
return timeAgo;
}
public static Map getPagination(PageInfo pageInfo) {
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
return pagination;
}
public static void main(String[] args){
LocalDate localDate = LocalDate.parse("2019-11-15");
ZoneId zone = ZoneId.systemDefault();
@ -117,4 +132,15 @@ public class Utils {
String s = getTimeAgo(Date.from(instant));
System.out.println(s);
}
public static Map getArticlesGlobalResult(PageInfo<ArticleDTO> pageInfo) {
Map map = new HashMap(2);
map.put("articles", pageInfo.getList());
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
map.put("pagination", pagination);
return map;
}
}

View File

@ -11,6 +11,7 @@ import com.rymcu.vertical.entity.User;
import com.rymcu.vertical.service.RoleService;
import com.rymcu.vertical.service.TopicService;
import com.rymcu.vertical.service.UserService;
import com.rymcu.vertical.util.Utils;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.*;
@ -34,13 +35,13 @@ public class AdminController {
private TopicService topicService;
@GetMapping("/users")
public GlobalResult users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
public GlobalResult<Map<String, Object>> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
PageHelper.startPage(page, rows);
List<User> list = userService.findAll();
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap(2);
PageInfo<User> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<String, Object>(2);
map.put("users", pageInfo.getList());
Map pagination = new HashMap(3);
Map<String, Number> pagination = new HashMap<>(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
@ -49,67 +50,61 @@ public class AdminController {
}
@GetMapping("/user/{idUser}/role")
public GlobalResult userRole(@PathVariable Integer idUser){
public GlobalResult<List<Role>> userRole(@PathVariable Integer idUser){
List<Role> roles = roleService.findByIdUser(idUser);
return GlobalResultGenerator.genSuccessResult(roles);
}
@GetMapping("/roles")
public GlobalResult roles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
public GlobalResult<Map<String, Object>> roles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
PageHelper.startPage(page, rows);
List<Role> list = roleService.findAll();
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap(2);
PageInfo<Role> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<String, Object>(2);
map.put("roles", pageInfo.getList());
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
}
@PatchMapping("/user/update-role")
public GlobalResult updateUserRole(@RequestBody UserRoleDTO userRole){
public GlobalResult<Map> updateUserRole(@RequestBody UserRoleDTO userRole){
Map map = userService.updateUserRole(userRole.getIdUser(),userRole.getIdRole());
return GlobalResultGenerator.genSuccessResult(map);
}
@PatchMapping("/user/update-status")
public GlobalResult updateUserStatus(@RequestBody User user){
public GlobalResult<Map> updateUserStatus(@RequestBody User user){
Map map = userService.updateStatus(user.getIdUser(),user.getStatus());
return GlobalResultGenerator.genSuccessResult(map);
}
@PatchMapping("/role/update-status")
public GlobalResult updateRoleStatus(@RequestBody Role role){
public GlobalResult<Map> updateRoleStatus(@RequestBody Role role){
Map map = roleService.updateStatus(role.getIdRole(),role.getStatus());
return GlobalResultGenerator.genSuccessResult(map);
}
@PostMapping("/role/post")
public GlobalResult addRole(@RequestBody Role role){
public GlobalResult<Map> addRole(@RequestBody Role role){
Map map = roleService.saveRole(role);
return GlobalResultGenerator.genSuccessResult(map);
}
@PutMapping("/role/post")
public GlobalResult updateRole(@RequestBody Role role){
public GlobalResult<Map> updateRole(@RequestBody Role role){
Map map = roleService.saveRole(role);
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/topics")
public GlobalResult topics(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
public GlobalResult<Map<String, Object>> topics(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows){
PageHelper.startPage(page, rows);
List<Topic> list = topicService.findAll();
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap(2);
PageInfo<Topic> pageInfo = new PageInfo<>(list);
Map<String, Object> map = new HashMap<>(2);
map.put("topics", pageInfo.getList());
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
Map pagination = Utils.getPagination(pageInfo);
map.put("pagination", pagination);
return GlobalResultGenerator.genSuccessResult(map);
}
@ -124,19 +119,19 @@ public class AdminController {
}
@GetMapping("/topic/detail/{idTopic}")
public GlobalResult topicDetail(@PathVariable Integer idTopic){
public GlobalResult<Topic> topicDetail(@PathVariable Integer idTopic){
Topic topic = topicService.findById(idTopic.toString());
return GlobalResultGenerator.genSuccessResult(topic);
}
@PostMapping("/topic/post")
public GlobalResult addTopic(@RequestBody Topic topic){
public GlobalResult<Map> addTopic(@RequestBody Topic topic){
Map map = topicService.saveTopic(topic);
return GlobalResultGenerator.genSuccessResult(map);
}
@PutMapping("/topic/post")
public GlobalResult updateTopic(@RequestBody Topic topic){
public GlobalResult<Map> updateTopic(@RequestBody Topic topic){
Map map = topicService.saveTopic(topic);
return GlobalResultGenerator.genSuccessResult(map);
}

View File

@ -12,6 +12,9 @@ import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.util.Map;
/**
* @author ronger
*/
@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {

View File

@ -13,6 +13,7 @@ import com.rymcu.vertical.service.ArticleService;
import com.rymcu.vertical.service.JavaMailService;
import com.rymcu.vertical.service.UserService;
import com.rymcu.vertical.util.UserUtils;
import com.rymcu.vertical.util.Utils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
@ -22,6 +23,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author ronger
*/
@RestController
@RequestMapping("/api/v1/console")
public class CommonApiController {
@ -35,8 +39,8 @@ public class CommonApiController {
@ApiOperation(value = "获取邮件验证码")
@PostMapping("/get-email-code")
public GlobalResult getEmailCode(@RequestParam("email") String email) throws MessagingException {
Map map = new HashMap();
public GlobalResult<Map<String, String>> getEmailCode(@RequestParam("email") String email) throws MessagingException {
Map<String, String> map = new HashMap<>(1);
map.put("message",GlobalResultMessage.SEND_SUCCESS.getMessage());
User user = userService.findByAccount(email);
if (user != null) {
@ -52,8 +56,8 @@ public class CommonApiController {
@ApiOperation(value = "获取找回密码邮件")
@PostMapping("/get-forget-password-email")
public GlobalResult getForgetPasswordEmail(@RequestParam("email") String email) throws MessagingException {
Map map = new HashMap<>(1);
public GlobalResult<Map<Object, Object>> getForgetPasswordEmail(@RequestParam("email") String email) throws MessagingException {
Map<Object, Object> map = new HashMap<>(1);
map.put("message",GlobalResultMessage.SEND_SUCCESS.getMessage());
User user = userService.findByAccount(email);
if (user != null) {
@ -68,13 +72,13 @@ public class CommonApiController {
}
@PostMapping("/register")
public GlobalResult register(@RequestParam("email") String email, @RequestParam("password") String password, @RequestParam("code") String code){
public GlobalResult<Map> register(@RequestParam("email") String email, @RequestParam("password") String password, @RequestParam("code") String code){
Map map = userService.register(email,password,code);
return GlobalResultGenerator.genSuccessResult(map);
}
@PostMapping("/login")
public GlobalResult login(@RequestParam("account") String account, @RequestParam("password") String password){
public GlobalResult<Map> login(@RequestParam("account") String account, @RequestParam("password") String password){
Map map = userService.login(account,password);
return GlobalResultGenerator.genSuccessResult(map);
}
@ -85,32 +89,26 @@ public class CommonApiController {
}
@GetMapping("/articles")
public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page,@RequestParam(defaultValue = "10") Integer rows,@RequestParam(defaultValue = "") String searchText,@RequestParam(defaultValue = "") String tag){
public GlobalResult<Map> 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.findArticles(searchText,tag);
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap(2);
map.put("articles", pageInfo.getList());
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
map.put("pagination", pagination);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/article/{id}")
public GlobalResult detail(@PathVariable Integer id){
public GlobalResult<Map<String, Object>> detail(@PathVariable Integer id){
ArticleDTO articleDTO = articleService.findArticleDTOById(id,1);
Map map = new HashMap<>(1);
Map<String, Object> map = new HashMap<>(1);
map.put("article", articleDTO);
return GlobalResultGenerator.genSuccessResult(map);
}
@GetMapping("/update/{id}")
public GlobalResult update(@PathVariable Integer id){
public GlobalResult<Map<String, Object>> update(@PathVariable Integer id){
ArticleDTO articleDTO = articleService.findArticleDTOById(id,2);
Map map = new HashMap<>(1);
map.put("article", articleDTO);
@ -118,13 +116,13 @@ public class CommonApiController {
}
@GetMapping("/token/{token}")
public GlobalResult token(@PathVariable String token){
public GlobalResult<TokenUser> token(@PathVariable String token){
TokenUser tokenUser = UserUtils.getTokenUser(token);
return GlobalResultGenerator.genSuccessResult(tokenUser);
}
@PatchMapping("/forget-password")
public GlobalResult forgetPassword(@RequestBody ForgetPasswordDTO forgetPassword){
public GlobalResult<Map> forgetPassword(@RequestBody ForgetPasswordDTO forgetPassword){
Map map = userService.forgetPassword(forgetPassword.getCode(), forgetPassword.getPassword());
return GlobalResultGenerator.genSuccessResult(map);
}

View File

@ -6,13 +6,16 @@ import com.rymcu.vertical.core.result.GlobalResult;
import com.rymcu.vertical.core.result.GlobalResultGenerator;
import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.service.ArticleService;
import com.rymcu.vertical.util.Utils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author ronger
*/
@RestController
@RequestMapping("/api/v1/tag")
public class TagController {
@ -24,14 +27,8 @@ public class TagController {
public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable String name){
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticlesByTagName(name);
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap(2);
map.put("articles", pageInfo.getList());
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
map.put("pagination", pagination);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
}
}

View File

@ -8,14 +8,16 @@ import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.entity.Topic;
import com.rymcu.vertical.service.ArticleService;
import com.rymcu.vertical.service.TopicService;
import com.rymcu.vertical.util.Utils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("ALL")
/**
* @author ronger
*/
@RestController
@RequestMapping("/api/v1/topic")
public class TopicController {
@ -34,14 +36,8 @@ public class TopicController {
public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @PathVariable String name){
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findArticlesByTopicName(name);
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap(2);
map.put("articles", pageInfo.getList());
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
map.put("pagination", pagination);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
}
}

View File

@ -8,14 +8,16 @@ import com.rymcu.vertical.dto.ArticleDTO;
import com.rymcu.vertical.dto.UserDTO;
import com.rymcu.vertical.service.ArticleService;
import com.rymcu.vertical.service.UserService;
import com.rymcu.vertical.util.Utils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author ronger
*/
@RestController
@RequestMapping("/api/v1/user")
public class UserController {
@ -39,14 +41,8 @@ public class UserController {
}
PageHelper.startPage(page, rows);
List<ArticleDTO> list = articleService.findUserArticlesByIdUser(userDTO.getIdUser());
PageInfo pageInfo = new PageInfo(list);
Map map = new HashMap(2);
map.put("articles", pageInfo.getList());
Map pagination = new HashMap(3);
pagination.put("pageSize",pageInfo.getPageSize());
pagination.put("total",pageInfo.getTotal());
pagination.put("currentPage",pageInfo.getPageNum());
map.put("pagination", pagination);
PageInfo<ArticleDTO> pageInfo = new PageInfo(list);
Map map = Utils.getArticlesGlobalResult(pageInfo);
return GlobalResultGenerator.genSuccessResult(map);
}