package com.heyu.api.controller.vv;


import com.heyu.api.common.annotation.AppRealyLogin;
import com.heyu.api.common.annotation.Describe;
import com.heyu.api.data.utils.R;
import com.heyu.api.oss.OssFileUploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/app/upload")

public class AppUploadOssController {

    @Autowired
    private OssFileUploadService ossFileUploadService;

    /**
     * post man 配置
     * https://blog.csdn.net/maowendi/article/details/80537304
     * <p>
     * <p>
     * http://localhost:8888/app/upload/file  file
     */
    // todo
    @Describe("app 上传图片")
    @PostMapping("/file")
    @AppRealyLogin
    public R uploadFile(HttpServletRequest request, HttpServletResponse response, @RequestParam("files") MultipartFile[] files) {
        List<Map<String, Object>> data = ossFileUploadService.uploadImages(files);
        return R.ok().setData(data);
    }
}