project backend

This commit is contained in:
Captain.B 2020-02-17 11:33:48 +08:00
parent 1862341e94
commit 1269d6b8af
2 changed files with 54 additions and 4 deletions

View File

@ -1,10 +1,12 @@
package io.metersphere.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.Project;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.service.ProjectService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@ -17,7 +19,28 @@ public class ProjectController {
@GetMapping("/listAll")
public List<Project> listAll() {
/// todo: 限制workspace和org
// todo: 限制workspace和org
return projectService.listAll();
}
@PostMapping("/add")
public Project addProject(@RequestBody Project project) {
return projectService.addProject(project);
}
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<Project>> getProjectList(@PathVariable int goPage, @PathVariable int pageSize) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, projectService.getProjectList());
}
@GetMapping("/delete/{projectId}")
public void deleteProject(@PathVariable(value = "projectId") String projectId) {
projectService.deleteProject(projectId);
}
@PostMapping("/update")
public void updateProject(@RequestBody Project Project) {
projectService.updateProject(Project);
}
}

View File

@ -7,6 +7,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;
@Service
@Transactional(rollbackFor = Exception.class)
@ -14,6 +15,32 @@ public class ProjectService {
@Resource
private ProjectMapper projectMapper;
public Project addProject(Project project) {
project.setId(UUID.randomUUID().toString());
long createTime = System.currentTimeMillis();
project.setCreateTime(createTime);
project.setUpdateTime(createTime);
// todo set workspace id
// project.setWorkspaceId();
projectMapper.insertSelective(project);
return project;
}
public List<Project> getProjectList() {
// todo 查询条件设置
return projectMapper.selectByExample(null);
}
public void deleteProject(String projectId) {
projectMapper.deleteByPrimaryKey(projectId);
}
public void updateProject(Project project) {
project.setCreateTime(null);// 创建时间禁止修改
project.setUpdateTime(System.currentTimeMillis());
projectMapper.updateByPrimaryKeySelective(project);
}
public List<Project> listAll() {
return projectMapper.selectByExample(null);
}