package cn.com.capcloud.api;

import cn.com.capcloud.api.action.ApiQueryAction;
import cn.com.capcloud.api.action.service.ExecuteService;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;

@CrossOrigin//支持跨域请求
@RestController
@RequestMapping("/api/data")
public class ApiQueryController {

    @Autowired
    private ApiQueryAction apiQueryAction;
    @Autowired
    private ExecuteService executeService;

    @RequestMapping("/myAction")
    public KHCResponseEntity myAction(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiQueryAction.myAction(jsonStr, request), true);
    }

    @RequestMapping("/page")
    public KHCResponseEntity page(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiQueryAction.page(jsonStr, request), false);
    }

    @RequestMapping("/list")
    public KHCResponseEntity list(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiQueryAction.list(jsonStr, request), false);
    }

    @RequestMapping("/showAll")
    public KHCResponseEntity showAll(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiQueryAction.showAll(jsonStr, request), false);
    }

    @RequestMapping("/findOne")
    public KHCResponseEntity findOne(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiQueryAction.findOne(jsonStr, request), true);
    }

    @RequestMapping("/showAllForTree")
    public KHCResponseEntity showAllForTree(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiQueryAction.showAllForTree(jsonStr, request), false);
    }

    @RequestMapping("/login")
    public KHCResponseEntity login(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiQueryAction.login(jsonStr, request), false);
    }

}
