package com.test.test.controller;

import java.util.List;

import com.test.test.domain.qo.IDQO;
import com.test.test.domain.qo.TestApiListQO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.enums.BusinessType;
import com.test.test.domain.TestApi;
import com.test.test.service.ITestApiService;
import com.test.common.core.page.TableDataInfo;

/**
 * 接口Controller
 */
@RestController
@RequestMapping("/test/api")
public class TestApiController extends BaseController {
    @Resource
    private ITestApiService testApiService;

    /**
     * 查询接口列表
     */
    @GetMapping("/list")
    public TableDataInfo list(@Validated TestApiListQO qo) {
        startPage();
        List<TestApi> list = testApiService.selectTestApiList(qo);
        return getDataTable(list);
    }

    /**
     * 获取接口详细信息
     */
    @PostMapping(value = "/detail")
    public AjaxResult getInfo(@RequestBody IDQO qo) {
        return success(testApiService.selectTestApiById(qo.getId()));
    }

    /**
     * 新增接口
     */
    @Log(title = "接口", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TestApi testApi) {
        return toAjax(testApiService.insertTestApi(testApi));
    }

    /**
     * 导入Swagger接口
     */
    @Log(title = "接口", businessType = BusinessType.INSERT)
    @PostMapping("/import/swagger")
    public AjaxResult importSwagger(@RequestParam(value = "url") String url) throws Exception {
        return toAjax(testApiService.importSwaggerApi(url));
    }
    /**
     * 修改接口
     */
    @Log(title = "接口", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TestApi testApi) {
        return toAjax(testApiService.updateTestApi(testApi));
    }

    /**
     * 删除接口
     */
    @Log(title = "接口", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public AjaxResult remove(@RequestBody IDQO qo) {
        return toAjax(testApiService.deleteTestApiById(qo.getId()));
    }


}
