mirror of https://github.com/halo-dev/halo
feat: add update status in batch api for post.
parent
f36f8aed8a
commit
68512988d0
|
@ -15,6 +15,7 @@ import run.halo.app.model.enums.PostStatus;
|
||||||
import run.halo.app.model.params.PostContentParam;
|
import run.halo.app.model.params.PostContentParam;
|
||||||
import run.halo.app.model.params.PostParam;
|
import run.halo.app.model.params.PostParam;
|
||||||
import run.halo.app.model.params.PostQuery;
|
import run.halo.app.model.params.PostQuery;
|
||||||
|
import run.halo.app.model.params.PostStatusUpdateParam;
|
||||||
import run.halo.app.model.vo.PostDetailVO;
|
import run.halo.app.model.vo.PostDetailVO;
|
||||||
import run.halo.app.service.OptionService;
|
import run.halo.app.service.OptionService;
|
||||||
import run.halo.app.service.PostService;
|
import run.halo.app.service.PostService;
|
||||||
|
@ -125,6 +126,12 @@ public class PostController {
|
||||||
return new BasePostMinimalDTO().convertFrom(post);
|
return new BasePostMinimalDTO().convertFrom(post);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("status")
|
||||||
|
@ApiOperation("Update post status in batch")
|
||||||
|
public List<Post> updateStatusInBatch(@RequestBody PostStatusUpdateParam param) {
|
||||||
|
return postService.updateStatusByIds(param.getIds(), param.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
@PutMapping("{postId:\\d+}/status/draft/content")
|
@PutMapping("{postId:\\d+}/status/draft/content")
|
||||||
@ApiOperation("Update draft")
|
@ApiOperation("Update draft")
|
||||||
public BasePostDetailDTO updateDraftBy(
|
public BasePostDetailDTO updateDraftBy(
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package run.halo.app.model.params;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import run.halo.app.model.enums.PostStatus;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post status update param.
|
||||||
|
*
|
||||||
|
* @author ryanwang
|
||||||
|
* @date 2019-12-12
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PostStatusUpdateParam {
|
||||||
|
|
||||||
|
private PostStatus status;
|
||||||
|
|
||||||
|
private List<Integer> ids;
|
||||||
|
}
|
|
@ -8,7 +8,6 @@ import run.halo.app.model.dto.post.BasePostDetailDTO;
|
||||||
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
||||||
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
import run.halo.app.model.dto.post.BasePostSimpleDTO;
|
||||||
import run.halo.app.model.entity.BasePost;
|
import run.halo.app.model.entity.BasePost;
|
||||||
import run.halo.app.model.entity.Post;
|
|
||||||
import run.halo.app.model.enums.PostStatus;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -236,4 +235,14 @@ public interface BasePostService<POST extends BasePost> extends CrudService<POST
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
POST updateStatus(@NonNull PostStatus status, @NonNull Integer postId);
|
POST updateStatus(@NonNull PostStatus status, @NonNull Integer postId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates post status by ids.
|
||||||
|
*
|
||||||
|
* @param ids post ids must not be null
|
||||||
|
* @param status post status must not be null
|
||||||
|
* @return updated posts
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
List<POST> updateStatusByIds(@NonNull List<Integer> ids, @NonNull PostStatus status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -380,6 +380,17 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public List<POST> updateStatusByIds(List<Integer> ids, PostStatus status) {
|
||||||
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return ids.stream().map(id -> {
|
||||||
|
return updateStatus(status, id);
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public POST create(POST post) {
|
public POST create(POST post) {
|
||||||
// Check title
|
// Check title
|
||||||
|
|
Loading…
Reference in New Issue