pull/137/head
ruibaby 2019-03-18 21:40:15 +08:00
parent a7511ffa1a
commit 55ab7815a9
6 changed files with 84 additions and 5 deletions

View File

@ -10,4 +10,10 @@ import cc.ryanc.halo.service.base.CrudService;
*/ */
public interface CategoryService extends CrudService<Category, Integer> { public interface CategoryService extends CrudService<Category, Integer> {
/**
* Remove category and relationship
*
* @param id id
*/
void remove(Integer id);
} }

View File

@ -1,7 +1,9 @@
package cc.ryanc.halo.service; package cc.ryanc.halo.service;
import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO; import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO;
import cc.ryanc.halo.model.entity.Category;
import cc.ryanc.halo.model.entity.Post; import cc.ryanc.halo.model.entity.Post;
import cc.ryanc.halo.model.entity.Tag;
import cc.ryanc.halo.model.enums.PostStatus; import cc.ryanc.halo.model.enums.PostStatus;
import cc.ryanc.halo.model.enums.PostType; import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.service.base.CrudService; import cc.ryanc.halo.service.base.CrudService;
@ -9,6 +11,8 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import java.util.List;
/** /**
* Post service. * Post service.
* *
@ -17,11 +21,26 @@ import org.springframework.lang.NonNull;
*/ */
public interface PostService extends CrudService<Post, Integer> { public interface PostService extends CrudService<Post, Integer> {
/**
* Save post with tags and categories
*
* @param post post
* @param tags tags
* @param categories categories
* @return saved post
*/
Post save(Post post, List<Tag> tags, List<Category> categories);
/**
* Remove post and relationship
* @param id id
*/
void remove(Integer id);
/** /**
* Lists latest posts. * Lists latest posts.
* *
* @param top top number must not be less than 0 * @param top top number must not be less than 0
*
* @return latest posts * @return latest posts
*/ */
@NonNull @NonNull
@ -30,10 +49,9 @@ public interface PostService extends CrudService<Post, Integer> {
/** /**
* List by status and type * List by status and type
* *
* @param status status * @param status status
* @param type type * @param type type
* @param pageable pageable * @param pageable pageable
*
* @return Page<PostSimpleOutputDTO> * @return Page<PostSimpleOutputDTO>
*/ */
@NonNull @NonNull
@ -43,7 +61,7 @@ public interface PostService extends CrudService<Post, Integer> {
* Count posts by status and type * Count posts by status and type
* *
* @param status status * @param status status
* @param type type * @param type type
* @return posts count * @return posts count
*/ */
Long countByStatus(PostStatus status, PostType type); Long countByStatus(PostStatus status, PostType type);

View File

@ -10,4 +10,11 @@ import cc.ryanc.halo.service.base.CrudService;
* @author johnniang * @author johnniang
*/ */
public interface TagService extends CrudService<Tag, Integer> { public interface TagService extends CrudService<Tag, Integer> {
/**
* Remove tag and relationship
*
* @param id id
*/
void remove(Integer id);
} }

View File

@ -21,4 +21,14 @@ public class CategoryServiceImpl extends AbstractCrudService<Category, Integer>
super(categoryRepository); super(categoryRepository);
this.categoryRepository = categoryRepository; this.categoryRepository = categoryRepository;
} }
/**
* Remove category and relationship
*
* @param id id
*/
@Override
public void remove(Integer id) {
// TODO 删除分类,以及和文章的对应关系
}
} }

View File

@ -1,7 +1,9 @@
package cc.ryanc.halo.service.impl; package cc.ryanc.halo.service.impl;
import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO; import cc.ryanc.halo.model.dto.post.PostSimpleOutputDTO;
import cc.ryanc.halo.model.entity.Category;
import cc.ryanc.halo.model.entity.Post; import cc.ryanc.halo.model.entity.Post;
import cc.ryanc.halo.model.entity.Tag;
import cc.ryanc.halo.model.enums.PostStatus; import cc.ryanc.halo.model.enums.PostStatus;
import cc.ryanc.halo.model.enums.PostType; import cc.ryanc.halo.model.enums.PostType;
import cc.ryanc.halo.repository.PostRepository; import cc.ryanc.halo.repository.PostRepository;
@ -14,6 +16,8 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import java.util.List;
/** /**
* Post service implementation. * Post service implementation.
* *
@ -30,6 +34,30 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
this.postRepository = postRepository; this.postRepository = postRepository;
} }
/**
* Save post with tags and categories
*
* @param post post
* @param tags tags
* @param categories categories
* @return saved post
*/
@Override
public Post save(Post post, List<Tag> tags, List<Category> categories) {
// TODO 保存文章以及对应标签和分类
return null;
}
/**
* Remove post and relationship
*
* @param id id
*/
@Override
public void remove(Integer id) {
// TODO 删除文章以及关联关系
}
@Override @Override
public Page<PostSimpleOutputDTO> listLatest(int top) { public Page<PostSimpleOutputDTO> listLatest(int top) {
Assert.isTrue(top > 0, "Top number must not be less than 0"); Assert.isTrue(top > 0, "Top number must not be less than 0");

View File

@ -21,4 +21,14 @@ public class TagServiceImpl extends AbstractCrudService<Tag, Integer> implements
super(tagRepository); super(tagRepository);
this.tagRepository = tagRepository; this.tagRepository = tagRepository;
} }
/**
* Remove tag and relationship
*
* @param id id
*/
@Override
public void remove(Integer id) {
// TODO 删除标签,以及对应的文章关系
}
} }