package cn.com.capcloud.api;

import cn.com.capcloud.api.action.ApiCrudAction;
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 ApiCrudController {

    @Autowired
    private ApiCrudAction apiCrudAction;
    @Autowired
    private ExecuteService executeService;

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

    //插入一条空数据
    @RequestMapping("/insertOne")
    public KHCResponseEntity insertOne(@RequestBody String jsonStr, HttpServletRequest request) {
        return executeService.execute(jsonStr, request, () -> apiCrudAction.insertOne(jsonStr, request), false);
    }

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

}
