package com.ruoyi.web.controller.common;

import com.ruoyi.common.core.domain.RestResponse;
import com.ruoyi.system.service.FileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * 通用请求处理
 *
 * @author ruoyi
 */
@Slf4j
@RestController
@Tag(name = "文件上传")
@RequiredArgsConstructor
@RequestMapping("/com")
public class CommonController
{



    private final FileService fileService;

    @Operation(summary = "上传课程相关图片", description = "上传图片,上传后返回原图和缩略图的url")
    @PostMapping("/courseImage/upload")
    public RestResponse uploadCourseImage(@RequestParam("file") MultipartFile file) {
        return new RestResponse().setData(fileService.uploadCourseImage(file));
    }

    @Operation(summary = "上传商城相关图片", description = "上传图片,上传后返回原图和缩略图的url")
    @PostMapping("/productImage/upload")
    public RestResponse uploadProductImage(@RequestParam("file") MultipartFile file) {
        return new RestResponse().setData(fileService.uploadProductImage(file)).setSuccess(true);
    }

    @Operation(summary = "上传文件", description = "上传文件，上传后返回文件url")
    @PostMapping("/file/upload")
    public RestResponse uploadFile(@RequestParam("file") MultipartFile file) {
        return new RestResponse().setSuccess(true).setCode(200).setData(fileService.uploadFile(file));
    }



}
