package com.roma.romaapi.controller;

import com.roma.romaapi.service.PageService;
import com.roma.romaapi.utils.CustomResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
public class PageController {

    @Autowired
    PageService pageService;
    // 获取页面的json
    @RequestMapping("/page/{code}")
    public Object pageJson(@PathVariable("code") String pageCode) {
        // 获取页面的json
        Map Response = CustomResponse.formatResponse(pageService.getPageJsonByCode(pageCode));
        Object data = Response.get("data");

        return data;
    }

    // 获取菜单----系统应用请求
    @RequestMapping("/page/menu")
    public Map menu() {
        Map<String, Object> ret = new HashMap<>();
        ret.put("children", pageService.menu());
        List<Map<String, Object>> pages = new ArrayList<Map<String, Object>>();
        pages.add(ret);
        Map lastMap = new HashMap<>();
        lastMap.put("pages", pages);

        return CustomResponse.formatResponse(lastMap);
    }
}
