mirror of https://github.com/halo-dev/halo
👽 代码优化
parent
0c3d0e2327
commit
e6fc40ca1a
|
@ -84,6 +84,15 @@ public interface PostRepository extends JpaRepository<Post, Long> {
|
|||
*/
|
||||
Post findPostByPostUrlAndPostType(String postUrl, String postType);
|
||||
|
||||
/**
|
||||
* 根据文章编号查询
|
||||
*
|
||||
* @param postId 文章编号
|
||||
* @param postType post or page
|
||||
* @return Post
|
||||
*/
|
||||
Post findPostByPostIdAndPostType(Long postId, String postType);
|
||||
|
||||
/**
|
||||
* 查询之后文章
|
||||
*
|
||||
|
|
|
@ -117,6 +117,15 @@ public interface PostService {
|
|||
*/
|
||||
Optional<Post> findByPostId(Long postId);
|
||||
|
||||
/**
|
||||
* 根据编号和类型查询文章
|
||||
*
|
||||
* @param postId postId
|
||||
* @param postType postType
|
||||
* @return Post
|
||||
*/
|
||||
Post findByPostId(Long postId, String postType);
|
||||
|
||||
/**
|
||||
* 根据文章路径查询
|
||||
*
|
||||
|
|
|
@ -192,6 +192,17 @@ public class PostServiceImpl implements PostService {
|
|||
return postRepository.findById(postId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据编号和类型查询文章
|
||||
*
|
||||
* @param postId postId
|
||||
* @return Post
|
||||
*/
|
||||
@Override
|
||||
public Post findByPostId(Long postId, String postType) {
|
||||
return postRepository.findPostByPostIdAndPostType(postId, postType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据文章路径查询
|
||||
*
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package cc.ryanc.halo.web.controller.api;
|
||||
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.BlogProperties;
|
||||
import cc.ryanc.halo.model.enums.ResponseStatus;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.Map;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/api/options")
|
||||
public class ApiOptionController {
|
||||
|
||||
@Autowired
|
||||
private OptionsService optionsService;
|
||||
|
||||
/**
|
||||
* 获取所有设置选项
|
||||
*
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping
|
||||
public JsonResult options() {
|
||||
Map<String, String> options = optionsService.findAllOptions();
|
||||
//去掉隐私元素
|
||||
options.remove(BlogProperties.MAIL_SMTP_HOST.getProp());
|
||||
options.remove(BlogProperties.MAIL_FROM_NAME.getProp());
|
||||
options.remove(BlogProperties.MAIL_SMTP_PASSWORD.getProp());
|
||||
options.remove(BlogProperties.MAIL_SMTP_USERNAME.getProp());
|
||||
options.remove(BlogProperties.MAIL_SMTP_USERNAME.getProp());
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个设置项
|
||||
*
|
||||
* @param optionName 设置选项名称
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{optionName}")
|
||||
public JsonResult option(@PathVariable(value = "optionName") String optionName) {
|
||||
String optionValue = optionsService.findOneOption(optionName);
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), optionValue);
|
||||
}
|
||||
}
|
|
@ -25,11 +25,12 @@ public class ApiPageController {
|
|||
/**
|
||||
* 获取单个页面
|
||||
*
|
||||
* @param postId postId
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{postUrl}")
|
||||
public JsonResult pages(@PathVariable(value = "postUrl") String postUrl) {
|
||||
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_PAGE.getDesc());
|
||||
@GetMapping(value = "/{postId}")
|
||||
public JsonResult pages(@PathVariable(value = "postId") Long postId) {
|
||||
Post post = postService.findByPostId(postId, PostType.POST_TYPE_PAGE.getDesc());
|
||||
if (null != post) {
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), post);
|
||||
} else {
|
||||
|
|
|
@ -66,12 +66,12 @@ public class ApiPostController {
|
|||
/**
|
||||
* 获取单个文章信息
|
||||
*
|
||||
* @param postUrl 文章路径
|
||||
* @param postId 文章编号
|
||||
* @return JsonResult
|
||||
*/
|
||||
@GetMapping(value = "/{postUrl}")
|
||||
public JsonResult posts(@PathVariable(value = "postUrl") String postUrl) {
|
||||
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_POST.getDesc());
|
||||
@GetMapping(value = "/{postId}")
|
||||
public JsonResult posts(@PathVariable(value = "postId") Long postId) {
|
||||
Post post = postService.findByPostId(postId, PostType.POST_TYPE_POST.getDesc());
|
||||
if (null != post) {
|
||||
return new JsonResult(ResponseStatus.SUCCESS.getCode(), ResponseStatus.SUCCESS.getMsg(), post);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue