package cn.reghao.oss.console.app.controller.page;

import cn.reghao.jutil.jdk.result.Result;
import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.console.app.model.dto.KeyAuthDto;
import cn.reghao.oss.console.app.service.UserKeyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author reghao
 * @date 2024-02-27 11:32:23
 */
@Api(tags = "oss key 认证接口")
@RestController
@RequestMapping("/api/oss/key")
public class KeyAuthController {
    private final UserKeyService userKeyService;

    public KeyAuthController(UserKeyService userKeyService) {
        this.userKeyService = userKeyService;
    }

    @ApiOperation(value = "认证 oss key")
    @PostMapping(value = "/auth", produces = MediaType.APPLICATION_JSON_VALUE)
    public String authKey(@Validated KeyAuthDto keyAuthDto) {
        Result result = userKeyService.auth(keyAuthDto);
        if (result.getCode() == 0) {
            return WebResult.success(result.getData());
        }

        return WebResult.result(result);
    }
}
