package net.northking.cctp.testbug.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.testbug.api.service.BugCorrelationLinkApiService;
import net.northking.cctp.testbug.dto.BugCorrelationLinkAddDto;
import net.northking.cctp.testbug.dto.BugLinkDeleteDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 缺陷关联表  bug_correlation_link
 */
@Api(tags = "缺陷管理关联表")
@RequestMapping("/public/batch/bugLink")
@RestController
public class BugRelationBatchCtrl {


    @Autowired
    private BugCorrelationLinkApiService apiService;

    /**
     * Restful接口-post： 批量新增缺陷管理关联表
     *
     * @param batch 集合
     * @return 主键集合
     */
    @ApiOperation(value = "新增：缺陷管理关联表")
    @PostMapping(
            value = "/insert",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<String> addBatch(
            @RequestBody @Validated BugCorrelationLinkAddDto batch) {
        ResultWrapper<String> wrapper = new ResultWrapper<>();
        String result = this.apiService.add(batch);
        return wrapper.success(result);
    }

    /**
     * Restful接口-post： 批量新增缺陷管理关联表
     *
     * @param batch 集合
     * @return 主键集合
     */
    @ApiOperation(value = "删除：缺陷管理关联表")
    @PostMapping(
            value = "/delete",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<Integer> deleteLink(
            @RequestBody BugLinkDeleteDto batch) {
        ResultWrapper<Integer> wrapper = new ResultWrapper<>();
        Integer result = this.apiService.removeByCode(batch);
        return wrapper.success(result);
    }

}
