package com.docus.server.controller;

import com.docus.server.service.IFileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 文件上传下载 API
 *
 * @author AutoGenerator
 * @since 2023-07-15
 */
@Api(value = "通用文件上传下载接口", tags = "通用文件上传下载接口")
@RestController
@RequestMapping("/sch/file")
public class FileController {
    @Resource
    private IFileUploadService iFileUploadService;

    @ApiOperation("文件下载")
    @GetMapping("/download")
//    @Override
    public void downloadFile(String filePath, HttpServletResponse response) throws Exception {
        iFileUploadService.downloadFile(filePath, response);
    }

    @ApiOperation("文件上传")
    @PostMapping("/upload")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "files", value = "文件", required = true, dataTypeClass = MultipartFile.class)
    })
//    @Override
    public void uploadFile(MultipartFile[] files, String pathKey) throws Exception {
        iFileUploadService.uploadFile(files, pathKey);
    }
}
