package com.jsc.oscm.controller;

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

import javax.annotation.Resource;

@RestController()
@RequestMapping("/target/api")
public class TargetApiController {
    @Resource
    private TargetApiService targetApiService;

    @PostMapping("/queryPageable/{index}/{size}")
    public String getTargetApiList(@RequestBody TargetApi targetApi, @PathVariable Integer index, @PathVariable Integer size) {
        return JSON.toJSONString(targetApiService.getTargetApiList(targetApi,index,size));
    }

    @GetMapping("/{id}")
    public String getTargetApiById(@PathVariable Integer id) {
        return JSON.toJSONString(targetApiService.getApiRulesInfoById(id));
    }

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

    @PostMapping("/save")
    public String save(@RequestBody TargetApi targetApi) {
        return JSON.toJSONString(targetApiService.save(targetApi));
    }

    @PostMapping("/delete")
    public String delete(@RequestBody TargetApi targetApi) {
        return JSON.toJSONString(targetApiService.delete(targetApi));
    }
}
