Skip to content

Commit

Permalink
🎨 remove ResponseStatusEnum.java and be instead of HttpStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed Feb 21, 2019
1 parent 1357196 commit c573c74
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 78 deletions.
4 changes: 1 addition & 3 deletions src/main/java/cc/ryanc/halo/logging/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,7 @@ public void warn(Marker marker, String format, Object arg1, Object arg2) {
}

@Override
public void warn(Marker marker, String

format, Object... arguments) {
public void warn(Marker marker, String format, Object... arguments) {
if (isWarnEnabled(marker)) {
proxy.warn(marker, format, arguments);
}
Expand Down
48 changes: 0 additions & 48 deletions src/main/java/cc/ryanc/halo/model/enums/ResponseStatusEnum.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ private static final class ByIdsSpecification<T> implements Specification<T> {
this.entityInformation = entityInformation;
}

@Override
public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<?> path = root.get(this.entityInformation.getIdAttribute());
this.parameter = cb.parameter(Iterable.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class AdminController extends BaseController {
* 请求后台页面
*
* @param model model
*
* @return 模板路径admin/admin_index
*/
@GetMapping(value = {"", "/index"})
Expand Down Expand Up @@ -117,6 +119,7 @@ public String index(Model model) {
* 处理跳转到登录页的请求
*
* @param session session
*
* @return 模板路径admin/admin_login
*/
@GetMapping(value = "/login")
Expand All @@ -135,6 +138,7 @@ public String login(HttpSession session) {
* @param loginName 登录名:邮箱/用户名
* @param loginPwd loginPwd 密码
* @param session session session
*
* @return JsonResult JsonResult
*/
@PostMapping(value = "/getLogin")
Expand Down Expand Up @@ -186,6 +190,7 @@ public JsonResult getLogin(@ModelAttribute("loginName") String loginName,
* 退出登录 销毁session
*
* @param session session
*
* @return 重定向到/admin/login
*/
@GetMapping(value = "/logOut")
Expand All @@ -201,6 +206,7 @@ public String logOut(HttpSession session) {
* 查看所有日志
*
* @param model model model
*
* @return 模板路径admin/widget/_logs-all
*/
@GetMapping(value = "/logs")
Expand Down Expand Up @@ -244,10 +250,9 @@ public String halo() {
@ResponseBody
public JsonResult getToken() {
final String token = (System.currentTimeMillis() + new Random().nextInt(999999999)) + "";
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), SecureUtil.md5(token));
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), HttpStatus.OK.getReasonPhrase(), SecureUtil.md5(token));
}


/**
* 小工具
*
Expand All @@ -273,6 +278,7 @@ public String markdownImport() {
*
* @param file file
* @param request request
*
* @return JsonResult
*/
@PostMapping(value = "/tools/markdownImport")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import cc.ryanc.halo.model.dto.Archive;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
import cc.ryanc.halo.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -75,9 +75,9 @@ public class ApiArchivesController {
public JsonResult archivesYear() {
final List<Archive> archives = postService.findPostGroupByYear();
if (!CollectionUtils.isEmpty(archives)) {
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), archives);
return new JsonResult(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), archives);
} else {
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
return new JsonResult(HttpStatus.NO_CONTENT.value(), HttpStatus.NO_CONTENT.getReasonPhrase());
}
}

Expand Down Expand Up @@ -132,6 +132,7 @@ public List<Archive> archivesYearAndMonth() {

/**
* @return JsonResult
*
* @Author Aquan
* @Description 返回所有文章
* @Date 2019.1.4 11:06
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

Expand Down Expand Up @@ -70,6 +73,7 @@ public List<Category> categories() {
* </p>
*
* @param cateUrl 分类路径
*
* @return JsonResult
*/
@GetMapping(value = "/{cateUrl}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ApiCommentController {
* @param comment comment
* @param postId postId
* @param request request
*
* @return JsonResult
*/
@PostMapping(value = "/save")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cc.ryanc.halo.web.controller.api;

import cc.ryanc.halo.model.domain.Gallery;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
import cc.ryanc.halo.service.GalleryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
* <pre>
Expand Down Expand Up @@ -81,6 +81,7 @@ public List<Gallery> galleries() {
* </p>
*
* @param id id
*
* @return JsonResult
*/
@GetMapping(value = "/{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package cc.ryanc.halo.web.controller.api;

import cc.ryanc.halo.model.domain.Link;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
import cc.ryanc.halo.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package cc.ryanc.halo.web.controller.api;

import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
import cc.ryanc.halo.service.OptionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

Expand Down Expand Up @@ -75,6 +76,7 @@ public Map<String, String> options() {
* </p>
*
* @param optionName 设置选项名称
*
* @return JsonResult
*/
@GetMapping(value = "/one")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import cc.ryanc.halo.exception.NotFoundException;
import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.PostTypeEnum;
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
import cc.ryanc.halo.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* <pre>
Expand Down Expand Up @@ -58,6 +59,7 @@ public class ApiPageController {
* </p>
*
* @param postId postId
*
* @return JsonResult
*/
@GetMapping(value = "/{postId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
import cc.ryanc.halo.model.enums.PostStatusEnum;
import cc.ryanc.halo.model.enums.PostTypeEnum;
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
import cc.ryanc.halo.service.PostService;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -15,7 +14,11 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cc.ryanc.halo.model.dto.HaloConst.OPTIONS;
import static org.springframework.data.domain.Sort.Direction.DESC;
Expand Down Expand Up @@ -98,6 +101,7 @@ public class ApiPostController {
* </p>
*
* @param page 页码
*
* @return JsonResult
*/
@GetMapping(value = "/page/{page}")
Expand All @@ -109,9 +113,9 @@ public JsonResult posts(@PathVariable(value = "page") Integer page, @SortDefault
final Pageable pageable = PageRequest.of(page - 1, size, sort);
final Page<Post> posts = postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc(), pageable);
if (null == posts) {
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
return new JsonResult(HttpStatus.NO_CONTENT.value(), HttpStatus.NO_CONTENT.getReasonPhrase());
}
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), posts);
return new JsonResult(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), posts);
}

/**
Expand Down Expand Up @@ -148,6 +152,7 @@ public JsonResult posts(@PathVariable(value = "page") Integer page, @SortDefault
* </p>
*
* @param postId 文章编号
*
* @return JsonResult
*/
@GetMapping(value = "/{postId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import cc.ryanc.halo.exception.NotFoundException;
import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.ResponseStatusEnum;
import cc.ryanc.halo.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

Expand Down Expand Up @@ -51,9 +54,9 @@ public class ApiTagController {
public JsonResult tags() {
final List<Tag> tags = tagService.listAll();
if (null != tags && tags.size() > 0) {
return new JsonResult(ResponseStatusEnum.SUCCESS.getCode(), ResponseStatusEnum.SUCCESS.getMsg(), tags);
return new JsonResult(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(), tags);
} else {
return new JsonResult(ResponseStatusEnum.EMPTY.getCode(), ResponseStatusEnum.EMPTY.getMsg());
return new JsonResult(HttpStatus.NO_CONTENT.value(), HttpStatus.NO_CONTENT.getReasonPhrase());
}
}

Expand All @@ -76,6 +79,7 @@ public JsonResult tags() {
* </p>
*
* @param tagUrl tagUrl
*
* @return JsonResult
*/
@GetMapping(value = "/{tagUrl}")
Expand Down

0 comments on commit c573c74

Please sign in to comment.