|
@@ -1,15 +1,17 @@
|
|
|
package com.mooctest.crowd.site.controller;
|
|
|
|
|
|
-import com.mooctest.crowd.site.command.CreateProjectCommand;
|
|
|
+import com.mooctest.crowd.domain.exception.BaseException;
|
|
|
import com.mooctest.crowd.site.command.ProjectDetailsCommand;
|
|
|
-import com.mooctest.crowd.site.constants.ResponseConstant;
|
|
|
-import com.mooctest.crowd.site.data.ResponseMessage;
|
|
|
import com.mooctest.crowd.site.data.dto.ProjectDetailsDTO;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-
|
|
|
+import com.mooctest.crowd.site.service.CrowdProjectService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.BindingResult;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -17,31 +19,44 @@ import java.util.List;
|
|
|
* @Email: 171256175@qq.com
|
|
|
* @date 2019-07-24 23:50
|
|
|
*/
|
|
|
-@RestController("/api")
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
public class CrowdProjectController {
|
|
|
|
|
|
- @RequestMapping(value = "/project", method = RequestMethod.POST)
|
|
|
- public Boolean createProject(CreateProjectCommand createProjectCommand){
|
|
|
- return null;
|
|
|
+ @Autowired
|
|
|
+ private CrowdProjectService projectService;
|
|
|
+
|
|
|
+ @RequestMapping(value = "/api/project", method = RequestMethod.POST)
|
|
|
+ public ProjectDetailsDTO createProject(@Validated @RequestBody ProjectDetailsCommand projectDetailsCommand, BindingResult result){
|
|
|
+ if (result.hasErrors())
|
|
|
+ throw new BaseException(result.getFieldErrors().toString());
|
|
|
+ else if (!projectDetailsCommand.isLegal())
|
|
|
+ throw new BaseException("信息不合法,项目可见性存在问题");
|
|
|
+ return projectService.createCrowdProject(projectDetailsCommand);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/project/{projectId}", method = RequestMethod.GET)
|
|
|
+ @RequestMapping(value = "/api/project/{projectId}", method = RequestMethod.GET)
|
|
|
public ProjectDetailsDTO getProject(@PathVariable("projectId") Long projectId){
|
|
|
- return null;
|
|
|
+ log.info("访问Project详情,projectId:"+projectId);
|
|
|
+ return projectService.getProjectDetails(projectId);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/project", method = RequestMethod.GET)
|
|
|
+ @RequestMapping(value = "/api/project", method = RequestMethod.GET)
|
|
|
public List<ProjectDetailsDTO> getProjects(){
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/project}", method = RequestMethod.PUT)
|
|
|
- public ProjectDetailsDTO updateProject(ProjectDetailsCommand projectDetailsCommand){
|
|
|
- return null;
|
|
|
+ @RequestMapping(value = "/api/project/{projectId}}", method = RequestMethod.PUT)
|
|
|
+ public ProjectDetailsDTO updateProject(@Validated @RequestBody ProjectDetailsCommand projectDetailsCommand, @PathVariable("projectId") Long projectId, BindingResult result){
|
|
|
+ if (result.hasErrors())
|
|
|
+ throw new BaseException(result.getFieldErrors().toString());
|
|
|
+ else if (!projectDetailsCommand.isLegal())
|
|
|
+ throw new BaseException("信息不合法,项目可见性存在问题");
|
|
|
+ return projectService.updateProject(projectId, projectDetailsCommand);
|
|
|
}
|
|
|
|
|
|
- @RequestMapping(value = "/project/{projectId}", method = RequestMethod.DELETE)
|
|
|
- public boolean deleteProject(@PathVariable("projectId") Long projectId){
|
|
|
- return true;
|
|
|
+ @RequestMapping(value = "/api/project/{projectId}", method = RequestMethod.DELETE)
|
|
|
+ public void deleteProject(@PathVariable("projectId") Long projectId, HttpSession session){
|
|
|
+ projectService.deleteProject(projectId, (Long)session.getAttribute("userId"));
|
|
|
}
|
|
|
}
|