package cn.reghao.autodop.dmaster.app.controller.config;

import cn.reghao.autodop.dmaster.app.model.po.config.build.CompilerConfig;
import cn.reghao.autodop.dmaster.app.service.config.CompilerConfigService;
import cn.reghao.jdkutil.result.Result;
import cn.reghao.jdkutil.result.WebBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2019-08-30 18:49:15
 */
@Slf4j
@Api(tags = "应用编译配置接口")
@RestController
@RequestMapping("/api/app/config/build/compiler")
public class CompilerConfigController {
    private final CompilerConfigService compilerConfigService;

    public CompilerConfigController(CompilerConfigService compilerConfigService) {
        this.compilerConfigService = compilerConfigService;
    }

    @ApiOperation(value = "添加/修改应用编译配置")
    @PostMapping(value = "/compiler", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addCompileConfig(@Validated CompilerConfig compilerConfig) {
        Integer id = compilerConfig.getId();
        Result result;
        if (id == null) {
            result = compilerConfigService.add(compilerConfig);
        } else {
            result = compilerConfigService.modify(compilerConfig);
        }
        return WebBody.result(result);
    }

    @ApiOperation(value = "删除应用编译配置")
    @DeleteMapping(value = "/compiler/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String deleteCompileConfig(@PathVariable("id") CompilerConfig compilerConfig) {
        Result result = compilerConfigService.delete(compilerConfig);
        return WebBody.result(result);
    }
}
