Search in sources :

Example 1 with JSONPatchMenuNodeRequest

use of de.metas.ui.web.menu.datatypes.json.JSONPatchMenuNodeRequest in project metasfresh-webui-api by metasfresh.

the class MenuRestController method patchNode.

@PatchMapping("/node/{nodeId}")
public List<JSONMenuNode> patchNode(@PathVariable(PARAM_NodeId) final String nodeId, @RequestBody final List<JSONDocumentChangedEvent> events) {
    userSession.assertLoggedIn();
    final JSONPatchMenuNodeRequest request = JSONPatchMenuNodeRequest.ofChangeEvents(events);
    final MenuTree menuTree = getMenuTree();
    final MenuNode node = menuTree.getNodeById(nodeId);
    final LinkedHashMap<String, MenuNode> changedMenuNodesById = new LinkedHashMap<>();
    if (request.getFavorite() != null) {
        menuTreeRepository.setFavorite(node, request.getFavorite());
        menuTree.streamNodesByAD_Menu_ID(node.getAD_Menu_ID()).forEach(changedNode -> changedMenuNodesById.put(changedNode.getId(), changedNode));
    }
    return JSONMenuNode.ofList(changedMenuNodesById.values(), menuTreeRepository);
}
Also used : JSONMenuNode(de.metas.ui.web.menu.datatypes.json.JSONMenuNode) JSONPatchMenuNodeRequest(de.metas.ui.web.menu.datatypes.json.JSONPatchMenuNodeRequest) LinkedHashMap(java.util.LinkedHashMap) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Aggregations

JSONMenuNode (de.metas.ui.web.menu.datatypes.json.JSONMenuNode)1 JSONPatchMenuNodeRequest (de.metas.ui.web.menu.datatypes.json.JSONPatchMenuNodeRequest)1 LinkedHashMap (java.util.LinkedHashMap)1 PatchMapping (org.springframework.web.bind.annotation.PatchMapping)1