package com.jsc.oscm.controller;

import com.alibaba.fastjson.JSON;
import com.jsc.oscm.entity.RulesApiParser;
import com.jsc.oscm.service.RulesApiParserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController()
@RequestMapping("/rules/api")
public class RulesApiParserController {
    @Resource
    private RulesApiParserService rulesApiParserService;

    @PostMapping("/queryPageable/{index}/{size}")
    public String getTargetApiList(@RequestBody RulesApiParser rulesApiParser, @PathVariable Integer index, @PathVariable Integer size) {
        return JSON.toJSONString(rulesApiParserService.getRulesApiParserList(rulesApiParser, index, size));
    }

    @GetMapping("/{id}")
    public String getRulesApiParserById(@PathVariable Integer id) {
        return JSON.toJSONString(rulesApiParserService.getRulesApiParserById(id));
    }

    @GetMapping("/queryAll")
    public String getAllTargetApi() {
        return JSON.toJSONString(rulesApiParserService.getAllRulesApiParser());
    }

    @PostMapping("/save")
    public String save(@RequestBody RulesApiParser rulesApiParser) {
        return JSON.toJSONString(rulesApiParserService.save(rulesApiParser));
    }

    @PostMapping("/delete")
    public String delete(@RequestBody RulesApiParser rulesApiParser) {
        return JSON.toJSONString(rulesApiParserService.delete(rulesApiParser));
    }
}
