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

import cn.reghao.autodop.dmaster.app.db.crud.config.PackerConfigCrud;
import cn.reghao.autodop.dmaster.app.model.po.config.build.PackerConfig;
import cn.reghao.autodop.dmaster.app.service.config.PackerConfigService;
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.http.ResponseEntity;
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/packer")
public class PackerConfigController {
    private final PackerConfigService packerConfigService;

    public PackerConfigController(PackerConfigService packerConfigService) {
        this.packerConfigService = packerConfigService;
    }

    @ApiOperation(value = "添加/修改应用打包配置")
    @PostMapping(value = "/packer", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addPackConfig(@Validated PackerConfig packerConfig) {
        Integer id = packerConfig.getId();
        Result result;
        if (id == null) {
            result = packerConfigService.add(packerConfig);
        } else {
            result = packerConfigService.modify(packerConfig);
        }
        return WebBody.result(result);
    }

    @ApiOperation(value = "删除应用打包配置")
    @DeleteMapping(value = "/packer/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String deletePackConfig(@PathVariable("id") PackerConfig packerConfig) {
        Result result = packerConfigService.delete(packerConfig);
        return WebBody.result(result);
    }
}
