package com.test.test.controller;

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.TestGroup;
import com.test.test.domain.qo.GroupDelectQO;
import com.test.test.service.ITestGroupService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/test/group")
public class TestGroupController extends BaseController {
    @Resource
    private ITestGroupService testGroupService;

    /**
     * 查询节点列表
     */
    @GetMapping("/list")
    public AjaxResult list(String type) {
        return success(testGroupService.selectTestGroupList(type));
    }

    /**
     * 新增节点
     */
    @Log(title = "节点", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TestGroup testGroup) {
        return success(testGroupService.insertTestGroup(testGroup));
    }

    /**
     * 修改节点
     */
    @Log(title = "节点", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TestGroup testGroup) {
        return toAjax(testGroupService.updateTestGroup(testGroup));
    }

    /**
     * 删除节点
     */
    @Log(title = "节点", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public AjaxResult remove(@RequestBody @Validated GroupDelectQO qo) throws Exception {
        return toAjax(testGroupService.deleteTestGroupById(qo));
    }
}
