package cn.fateverse.workflow.controller;

import cn.fateverse.common.core.result.Result;
import cn.fateverse.workflow.entity.bpmn.Attachment;
import cn.fateverse.workflow.service.ProcessFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 工作流模块文件上传
 *
 * @author Clay
 * @date 2023/1/10
 */

@Api(value = "工作流文件上传", tags = "工作流文件上传")
@RestController
@RequestMapping("/process/file")
public class ProcessFileController {

    private final ProcessFileService processFileService;

    public ProcessFileController(ProcessFileService processFileService) {
        this.processFileService = processFileService;
    }

    @ApiOperation("上传文件")
    @PostMapping
    public Result<Attachment> uploadFile(MultipartFile file) throws Exception {
        Attachment attachment = processFileService.uploadFile(file);
        return Result.ok(attachment);
    }

    @ApiOperation("删除文件")
    @DeleteMapping("/{fileId}")
    public Result<Void> deleteFile(@PathVariable Long fileId) {
        processFileService.deleteFile(fileId);
        return Result.ok();
    }

}
