package com.ytpm.middle.controller;

import com.ytpm.attach.Attach;
import com.ytpm.attach.Image;
import com.ytpm.general.Result;
import com.ytpm.middle.service.AttachService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;

import javax.annotation.Resource;

@Api(tags = "文件管理")
@Slf4j(topic = "attach-controller")
@RequestMapping("/attach")
@RestController
public class AttachController {
    @Resource
    private AttachService attachService;

    /**
     * 图片上传
     */
    @ApiOperation("图片上传")
    @PostMapping("/image")
    public Result<Image> uploadImg(@RequestParam("file") MultipartFile multipartFile) {
        return Result.resultObjOk(attachService.uploadImage(multipartFile));
    }

    /**
     * 上传文件
     */
    @ApiOperation("文件上传")
    @PostMapping( "/file")
    public Result<Attach> upload(@RequestParam("file") MultipartFile multipartFile) {
        return Result.resultObjOk(attachService.uploadFile(multipartFile));
    }

}
