mirror of https://github.com/halo-dev/halo
Add an API to update categories in batch (#1657)
* feat: Add a api of update categories in batch * fix: filter conditionpull/1666/head
parent
15bde8eef7
commit
acf6a98d25
|
@ -1,10 +1,11 @@
|
|||
package run.halo.app.controller.admin.api;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.ASC;
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.validation.Valid;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
|
@ -89,6 +90,20 @@ public class CategoryController {
|
|||
return categoryService.convertTo(categoryService.update(categoryToUpdate));
|
||||
}
|
||||
|
||||
@PutMapping("/batch")
|
||||
@ApiOperation("Updates category in batch")
|
||||
public List<CategoryDTO> updateBatchBy(@RequestBody List<@Valid CategoryParam> categoryParams) {
|
||||
List<Category> categoriesToUpdate = categoryParams.stream()
|
||||
.filter(categoryParam -> Objects.nonNull(categoryParam.getId()))
|
||||
.map(categoryParam -> {
|
||||
Category categoryToUpdate = categoryService.getById(categoryParam.getId());
|
||||
categoryParam.update(categoryToUpdate);
|
||||
return categoryToUpdate;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return categoryService.convertTo(categoryService.updateInBatch(categoriesToUpdate));
|
||||
}
|
||||
|
||||
@DeleteMapping("{categoryId:\\d+}")
|
||||
@ApiOperation("Deletes category")
|
||||
public void deletePermanently(@PathVariable("categoryId") Integer categoryId) {
|
||||
|
|
|
@ -14,11 +14,14 @@ import run.halo.app.utils.SlugUtils;
|
|||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @author guqing
|
||||
* @date 2019-03-21
|
||||
*/
|
||||
@Data
|
||||
public class CategoryParam implements InputConverter<Category> {
|
||||
|
||||
private Integer id;
|
||||
|
||||
@NotBlank(message = "分类名称不能为空")
|
||||
@Size(max = 255, message = "分类名称的字符长度不能超过 {max}")
|
||||
private String name;
|
||||
|
|
Loading…
Reference in New Issue