package com.storlead.system.controller;

import com.storlead.framework.common.result.Result;
import com.storlead.system.pojo.entity.SystemOssConfigEntity;
import com.storlead.system.pojo.entity.SystemPersonalizeSettingEntity;
import com.storlead.system.service.SystemOssConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * OSS  secret 配置 前端控制器
 * </p>
 *
 * @author chenkq
 * @since 2022-07-20
 */
@RestController
@RequestMapping("/sys/alioss/config")
@Api(tags = "平台中心 - 系统: OSS配置")
public class SystemOssConfigApiController {

    @Resource
    private SystemOssConfigService systemOssConfigService;

    @PostMapping(value = "/saveAlioss")
    @ApiOperation(value = "配置系统基础设置", notes = "配置系统基础设置")
    @ApiResponses({
            @ApiResponse(code = 200, message = "", response = SystemPersonalizeSettingEntity.class)
    })
    public Result saveSetting(SystemOssConfigEntity entity) {
        systemOssConfigService.saveOrUpdate(entity);
        return Result.ok();
    }

    @PostMapping(value = "/getAlioss")
    @ApiOperation(value = "获取系统基础设置", notes = "获取系统基础设置")
    @ApiResponses({
            @ApiResponse(code = 200, message = "", response = SystemPersonalizeSettingEntity.class)
    })
    public Result<?> getSetting() {
        SystemOssConfigEntity alioss = systemOssConfigService.getOne(null);
        return Result.result(alioss);
    }
}
