Remove deprecated code(#106)

pull/137/head
johnniang 2019-03-04 13:33:33 +08:00
parent 7a1c3234d9
commit 41d55d94cc
1 changed files with 5 additions and 46 deletions

View File

@ -1,9 +1,7 @@
package cc.ryanc.halo.web.controller.api;
import cc.ryanc.halo.exception.NotFoundException;
import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.enums.PostStatusEnum;
import cc.ryanc.halo.model.enums.PostTypeEnum;
@ -20,6 +18,8 @@ import org.springframework.data.web.SortDefault;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.util.Optional;
import static cc.ryanc.halo.utils.HaloUtils.getDefaultPageSize;
import static org.springframework.data.domain.Sort.Direction.DESC;
@ -171,11 +171,9 @@ public class ApiPostController {
*/
@GetMapping(value = "/{postId}")
public Post posts(@PathVariable(value = "postId") Long postId) {
final Post post = postService.findByPostId(postId, PostTypeEnum.POST_TYPE_POST.getDesc());
if (post == null) {
throw new NotFoundException("Post with id: " + postId + " was not found").setErrorData(postId);
}
// Find post by post id
Post post = Optional.ofNullable(postService.findByPostId(postId, PostTypeEnum.POST_TYPE_POST.getDesc()))
.orElseThrow(() -> new NotFoundException("Post with id: " + postId + " was not found").setErrorData(postId));
// Cache views
postService.cacheViews(post.getPostId());
@ -183,43 +181,4 @@ public class ApiPostController {
return post;
}
/**
*
*
* @param cateUrl
* @param page
* @return String
*/
@GetMapping(value = "/categories/{cateUrl}/{page}")
@Deprecated
public JsonResult categories(@PathVariable("cateUrl") String cateUrl,
@PathVariable("page") Integer page,
@SortDefault(sort = "postDate", direction = DESC) Sort sort) {
final Category category = categoryService.findByCateUrl(cateUrl);
final Pageable pageable = PageRequest.of(page - 1, getDefaultPageSize(), sort);
final Page<Post> posts = postService.findPostByCategories(category, pageable);
return JsonResult.ok(HttpStatus.OK.getReasonPhrase(), posts);
}
/**
*
*
* @param tagUrl
* @param page
* @return String
*/
@GetMapping(value = "/tags/{tagUrl}/{page}")
@Deprecated
public JsonResult tags(@PathVariable("tagUrl") String tagUrl,
@PathVariable("page") Integer page,
@SortDefault(sort = "postDate", direction = DESC) Sort sort) {
final Tag tag = tagService.findByTagUrl(tagUrl);
final Pageable pageable = PageRequest.of(page - 1, getDefaultPageSize(), sort);
final Page<Post> posts = postService.findPostsByTags(tag, pageable);
return JsonResult.ok(HttpStatus.OK.getReasonPhrase(), posts);
}
}