package cn.iocoder.yudao.module.system.api.project;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.project.dto.ProjectDTO;
import cn.iocoder.yudao.module.system.controller.admin.project.vo.ProjectSaveReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.project.ProjectDO;
import cn.iocoder.yudao.module.system.service.project.ProjectService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class ProjectApiImpl implements ProjectApi {

    @Resource
    private ProjectService projectService;

    @Override
    public CommonResult<Long> create(ProjectDTO createReqVO) {
        return success(projectService.createProject(BeanUtils.toBean(createReqVO, ProjectSaveReqVO.class)));
    }

    @Override
    public CommonResult<ProjectDTO> getProject(String projectNo) {
        ProjectDO projectDO = projectService.getProject(projectNo);
        return success(BeanUtils.toBean(projectDO, ProjectDTO.class));
    }

    @Override
    public CommonResult<List<ProjectDTO>> getProjectList(Collection<String> projectNos) {
        List<ProjectDO> projectDOList = projectService.getProjectList(projectNos);
        return success(BeanUtils.toBean(projectDOList, ProjectDTO.class));
    }
}
