package ink.wgink.common.controller.api.env;

import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.common.pojo.dtos.env.EnvDTO;
import ink.wgink.common.pojo.vos.env.EnvListVO;
import ink.wgink.common.service.env.IEnvService;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.result.ErrorResult;
import ink.wgink.pojo.result.SuccessResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: EnvController
 * @Description: 环境变量
 * @Author: wanggeng
 * @Date: 2022/5/16 10:50
 * @Version: 1.0
 */
@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "环境变量")
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/env")
public class EnvController extends DefaultBaseController {

    @Autowired
    private IEnvService envService;

    @ApiOperation(value = "更新", notes = "更新")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PutMapping("update")
    @CheckRequestBodyAnnotation
    public SuccessResult update(@RequestBody EnvListVO envListVO) {
        envService.update(envListVO);
        return new SuccessResult();
    }

    @ApiOperation(value = "获取配置", notes = "获取配置接口")
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @GetMapping("list")
    public List<EnvDTO> list() {
        return envService.list();
    }

}
