mirror of https://github.com/halo-dev/halo
feat: support remove in batch api for post.
parent
bd2eebf1cd
commit
a55b469ae4
|
@ -1,7 +1,6 @@
|
|||
package run.halo.app.controller.admin.api;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -17,7 +16,6 @@ import run.halo.app.model.params.PostContentParam;
|
|||
import run.halo.app.model.params.PostParam;
|
||||
import run.halo.app.model.params.PostQuery;
|
||||
import run.halo.app.model.vo.PostDetailVO;
|
||||
import run.halo.app.model.vo.PostListVO;
|
||||
import run.halo.app.service.OptionService;
|
||||
import run.halo.app.service.PostService;
|
||||
|
||||
|
@ -140,10 +138,15 @@ public class PostController {
|
|||
|
||||
@DeleteMapping("{postId:\\d+}")
|
||||
public void deletePermanently(@PathVariable("postId") Integer postId) {
|
||||
// Remove it
|
||||
postService.removeById(postId);
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@ApiOperation("Delete posts permanently in batch by id array")
|
||||
public List<Post> deletePermanentlyInBatch(@RequestBody List<Integer> ids) {
|
||||
return postService.removeByIds(ids);
|
||||
}
|
||||
|
||||
@GetMapping(value = {"preview/{postId:\\d+}", "{postId:\\d+}/preview"})
|
||||
@ApiOperation("Get preview link")
|
||||
public String preview(@PathVariable("postId") Integer postId) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package run.halo.app.model.entity;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
|
@ -12,5 +14,6 @@ import javax.persistence.Entity;
|
|||
*/
|
||||
@Entity(name = "PostMeta")
|
||||
@DiscriminatorValue("0")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PostMeta extends BaseMeta {
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import run.halo.app.model.vo.PostDetailVO;
|
|||
import run.halo.app.model.vo.PostListVO;
|
||||
import run.halo.app.service.base.BasePostService;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -94,6 +95,15 @@ public interface PostService extends BasePostService<Post> {
|
|||
@Override
|
||||
Post getBy(@NonNull PostStatus status, @NonNull String url);
|
||||
|
||||
/**
|
||||
* Removes posts in batch.
|
||||
*
|
||||
* @param ids ids must not be null.
|
||||
* @return a list of deleted post.
|
||||
*/
|
||||
@NonNull
|
||||
List<Post> removeByIds(@NonNull Collection<Integer> ids);
|
||||
|
||||
/**
|
||||
* Lists year archives.
|
||||
*
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.springframework.lang.Nullable;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import run.halo.app.event.logger.LogEvent;
|
||||
import run.halo.app.event.post.PostVisitEvent;
|
||||
import run.halo.app.model.dto.BaseMetaDTO;
|
||||
|
@ -159,6 +160,14 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
return post;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Post> removeByIds(Collection<Integer> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return ids.stream().map(this::removeById).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Post getByUrl(String url) {
|
||||
Post post = super.getByUrl(url);
|
||||
|
|
Loading…
Reference in New Issue