package com.ruoyi.web.work.api;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.work.api.config.BaseController;
import com.ruoyi.web.work.domain.TaskList;
import com.ruoyi.web.work.domain.dto.TaskListDto;
import com.ruoyi.web.work.service.ITaskListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 任务进度列
 *
 * @author lsw
 * @date 2024-07-03
 */
@RestController
@RequestMapping("/app/task")
public class Api_TaskListController extends BaseController {
    @Autowired
    private ITaskListService taskListService;

    @GetMapping("/list")
    public AjaxResult list(TaskList taskList) {
        if (taskList.getRole() == null) {
            taskList.setUserId(getUser().getId());
        } else {
            //0甲方，1乙方
            if (taskList.getRole() == 0) {
                taskList.setEnterpriseId(getUser().getId());
            } else {
                taskList.setUserId(getUser().getId());
            }
        }
        return AjaxResult.success(taskListService.selectList(taskList));
    }

    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody TaskListDto dto) {
        return taskListService.add(dto);
    }

    @GetMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return taskListService.remove(id);
    }
}
