package com.eitc.modules.devtools.controller;

import com.google.gson.Gson;
import com.eitc.common.constant.Constant;
import com.eitc.common.utils.Result;
import com.eitc.modules.devtools.entity.GenParam;
import com.eitc.modules.sys.service.SysParamsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 代码生成参数配置
 *
 * @author Mark eitc@163.com
 */
@RestController
@RequestMapping("devtools/param")
public class GenParamController {
    @Autowired
    private SysParamsService sysParamsService;

    @GetMapping("info")
    public Result<GenParam> info(){
        GenParam param = sysParamsService.getValueObject(Constant.DEV_TOOLS_PARAM_KEY, GenParam.class);

        return new Result<GenParam>().ok(param);
    }

    @PostMapping
    public Result saveConfig(@RequestBody GenParam param){
        sysParamsService.updateValueByCode(Constant.DEV_TOOLS_PARAM_KEY, new Gson().toJson(param));

        return new Result();
    }
}