package com.ruoyi.web.controller.zdsz;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.obs.ObsService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 华为obs
 *
 * @date 2021-11-24
 */
@Validated
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/obs")
public class ObsController extends BaseController {
    private final ObsService obsService;

    /**
     * 上传文件
     */
    @Log(title = "OBS对象存储", businessType = BusinessType.INSERT)
    @PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R uploadFile(@RequestPart("file") MultipartFile file) throws Exception {
        return R.ok(obsService.uploadFile(file));
    }

    /**
     * 删除文件
     */
    @DeleteMapping("/{objectKey}")
    public R deleteFile(@PathVariable String objectKey) throws Exception {
        obsService.deleteFile(objectKey);
        return R.ok();
    }

}
