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.ProjectUserVO;
import cn.cslg.pas.common.utils.Response;
import cn.cslg.pas.common.utils.auth.checkAuth;
import cn.cslg.pas.domain.ProjectUser;
import cn.cslg.pas.service.ProjectUserService;
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 java.io.IOException;

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

    private final ProjectUserService projectUserService;

    @GetMapping("list")
    @Operation(summary = "成员列表")
    public String getPageList(ProjectUserVO params) throws IOException {
        return Response.success(projectUserService.getPageList(params));
    }

    @checkAuth(FunId = "/workspace/project/assign_participants/add")
    @PostMapping("add")
    @Operation(summary = "新增成员")
    public String add(@RequestBody ProjectUser projectUser) {
        return projectUserService.add(projectUser);
    }


    @checkAuth(FunId = "/workspace/project/assign_participants/modify")
    @PostMapping("edit")
    @Operation(summary = "编辑成员")
    public String edit(@RequestBody ProjectUser projectUser) {
        return projectUserService.edit(projectUser);
    }


    @checkAuth(FunId = "/workspace/project/assign_participants/remove")
    @PostMapping("delete")
    @Operation(summary = "删除成员")
    public String delete(Integer id) {
        return projectUserService.delete(id);
    }
}
