Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a api of update categories in batch #1657

Merged
merged 3 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

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;
Expand Down Expand Up @@ -89,6 +91,20 @@ public CategoryDTO updateBy(@PathVariable("categoryId") Integer categoryId,
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.isNull(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) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/run/halo/app/model/params/CategoryParam.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
*
* @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;
Expand Down