mirror of https://github.com/halo-dev/halo
Fixed remove menu error.
parent
cb06e7c842
commit
12846a4c5d
|
@ -79,6 +79,13 @@ public class MenuController {
|
|||
@DeleteMapping("{menuId:\\d+}")
|
||||
@ApiOperation("Deletes a menu")
|
||||
public MenuDTO deleteBy(@PathVariable("menuId") Integer menuId) {
|
||||
List<Menu> menus = menuService.listByParentId(menuId);
|
||||
if (null != menus && menus.size() > 0) {
|
||||
menus.forEach(menu -> {
|
||||
menu.setParentId(0);
|
||||
menuService.update(menu);
|
||||
});
|
||||
}
|
||||
return new MenuDTO().convertFrom(menuService.removeById(menuId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import org.springframework.lang.NonNull;
|
|||
import run.halo.app.model.entity.Menu;
|
||||
import run.halo.app.repository.base.BaseRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Menu repository.
|
||||
*
|
||||
|
@ -14,4 +16,6 @@ public interface MenuRepository extends BaseRepository<Menu, Integer> {
|
|||
boolean existsByName(@NonNull String name);
|
||||
|
||||
boolean existsByIdNotAndName(@NonNull Integer id, @NonNull String name);
|
||||
|
||||
List<Menu> findByParentId(@NonNull Integer id);
|
||||
}
|
||||
|
|
|
@ -44,4 +44,12 @@ public interface MenuService extends CrudService<Menu, Integer> {
|
|||
* @return a menu tree
|
||||
*/
|
||||
List<MenuVO> listAsTree(Sort sort);
|
||||
|
||||
/**
|
||||
* Lists menu by parent id.
|
||||
*
|
||||
* @param id id
|
||||
* @return a list of menu
|
||||
*/
|
||||
List<Menu> listByParentId(@NonNull Integer id);
|
||||
}
|
||||
|
|
|
@ -71,6 +71,13 @@ public class MenuServiceImpl extends AbstractCrudService<Menu, Integer> implemen
|
|||
return topLevelMenu.getChildren();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Menu> listByParentId(Integer id) {
|
||||
Assert.notNull(id, "Menu parent id must not be null");
|
||||
|
||||
return menuRepository.findByParentId(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Menu create(Menu menu) {
|
||||
nameMustNotExist(menu);
|
||||
|
|
Loading…
Reference in New Issue