package cn.cslg.pas.controller;

import cn.cslg.pas.common.core.annotation.Permission;
import cn.cslg.pas.common.core.base.Constants;
import cn.cslg.pas.common.model.vo.ProjectFileVO;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.common.utils.auth.checkAuth;
import cn.cslg.pas.domain.ProjectFile;
import cn.cslg.pas.service.ProjectFileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 专题库附件 前端控制器
 * </p>
 *
 * @author 王岩
 * @since 2021-12-24
 */
@Tag(name = "专题库附件")
@RestController
@RequestMapping(Constants.API_VERSION_V2 + "/project/file")
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
public class ProjectFileController {

    private final ProjectFileService projectFileService;

    @GetMapping("list")
    @Operation(summary = "附件列表")
    public String getPageList(ProjectFileVO params) throws IOException {
        return Response.success(projectFileService.getPageList(params));
    }

    @Permission(roles = {2})
    @checkAuth(FunId = "/workspace/project/report_manage/add")
    @PostMapping("add")
    @Operation(summary = "新增附件")
    public String add(ProjectFile projectFile, MultipartFile file) {
        return projectFileService.add(projectFile, file);
    }

    @Permission(roles = {2})
    @checkAuth(FunId = "/workspace/project/report_manage/modify")
    @PostMapping("edit")
    @Operation(summary = "编辑附件")
    public String edit(ProjectFile projectFile, MultipartFile file) {
        return projectFileService.edit(projectFile, file);
    }

    @Permission(roles = {2})
    @checkAuth(FunId = "/workspace/project/report_manage/delete")
    @PostMapping("delete")
    @Operation(summary = "删除附件")
    public String delete(Integer id) {
        return projectFileService.delete(id);
    }

}
