package com.playlet.web.controller.tool;

import com.playlet.common.core.domain.Result;
import com.playlet.web.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>文件上传</p>
 * @author clunt
 */
@RestController
@Api(tags = "通用*文件上传")
@RequestMapping(value = "/tool/oss")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OssFileController {

    private final OssService ossService;

    @ResponseBody
    @PostMapping(value = "/upload")
    @ApiOperation(value = "文件上传接口,返回文件的url地址", httpMethod = "POST")
    public Result<String> upload(@RequestPart @RequestParam("file") MultipartFile multipartFile) {
        try {
            return Result.success(ossService.upload(multipartFile));
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

}
