@RequestMapping(value = "/search", method = RequestMethod.GET) public ResponseEntity<PagedResources<ProjectResource>> searchProjects( @PageableDefault Pageable pageable, @RequestParam(required = false) String searchBy, PagedResourcesAssembler<Project> assembler) throws NotAuthenticatedException { Page<Project> pageResult = projectQueryService.findBy(pageable, searchBy); PagedResources<ProjectResource> resources = assembler.toResource(pageResult, projectResourceAssembler); return new ResponseEntity<>(resources, HttpStatus.OK); }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public ResponseEntity<ProjectResource> get(@PathVariable String id) throws ProjectNotFoundException { Project project = projectQueryService.findBy(new ProjectId(id)); return new ResponseEntity<>(projectResourceAssembler.toResource(project), HttpStatus.OK); }
@RequestMapping(value = "/{id}", method = RequestMethod.GET) public ResponseEntity<ProjectResource> get(@PathVariable String id) throws ProjectNotFoundException { Project project = projectQueryService.findBy(new ProjectId(id)); return new ResponseEntity<>(projectResourceAssembler.toResource(project), HttpStatus.OK); }
@RequestMapping(value = "/search", method = RequestMethod.GET) public ResponseEntity<PagedResources<ProjectResource>> searchProjects( @PageableDefault Pageable pageable, @RequestParam(required = false) String searchBy, PagedResourcesAssembler<Project> assembler) throws NotAuthenticatedException { Page<Project> pageResult = projectQueryService.findBy(pageable, searchBy); PagedResources<ProjectResource> resources = assembler.toResource(pageResult, projectResourceAssembler); return new ResponseEntity<>(resources, HttpStatus.OK); }
@RequestMapping(value = "/{id}/stakeholders/{stakeholderId}", method = RequestMethod.DELETE) public ResponseEntity<ProjectResource> removeStakeholder(@PathVariable String id, @PathVariable String stakeholderId) throws ProjectNotFoundException, BindException { Project project = projectQueryService.findBy(new ProjectId(id)); Stakeholder toRemove = null; for (Stakeholder stakeholder : project.getStakeholders()) { if (stakeholder.getId().equals(stakeholderId)) { toRemove = stakeholder; break; } } if (toRemove != null) { project = projectCommandService.removeStakeholder(new ProjectId(id), toRemove); } return new ResponseEntity<>(projectResourceAssembler.toResource(project), HttpStatus.OK); }
@RequestMapping(value = "/{id}/stakeholders/{stakeholderId}", method = RequestMethod.DELETE) public ResponseEntity<ProjectResource> removeStakeholder(@PathVariable String id, @PathVariable String stakeholderId) throws ProjectNotFoundException, BindException { Project project = projectQueryService.findBy(new ProjectId(id)); Stakeholder toRemove = null; for (Stakeholder stakeholder : project.getStakeholders()) { if (stakeholder.getId().equals(stakeholderId)) { toRemove = stakeholder; break; } } if (toRemove != null) { project = projectCommandService.removeStakeholder(new ProjectId(id), toRemove); } return new ResponseEntity<>(projectResourceAssembler.toResource(project), HttpStatus.OK); }
@RequestMapping(value = "/{id}/stakeholders", method = RequestMethod.POST) public ResponseEntity<ProjectResource> addStakeholder(@PathVariable String id, @RequestBody StakeholderPod pod, BindingResult bindingResult) throws ProjectNotFoundException, BindException { if (bindingResult.hasErrors()) { throw new BindException(bindingResult); } Project project = projectQueryService.findBy(new ProjectId(id)); project = projectCommandService.addStakeholder(new ProjectId(id), new Stakeholder(project.getTenantId(), pod.getName(), StakeholderType.INTERNAL, pod.getRole(), StakeholderClassification.NEUTRAL)); return new ResponseEntity<>(projectResourceAssembler.toResource(project), HttpStatus.OK); }
@RequestMapping(value = "/{id}/stakeholders", method = RequestMethod.POST) public ResponseEntity<ProjectResource> addStakeholder(@PathVariable String id, @RequestBody StakeholderPod pod, BindingResult bindingResult) throws ProjectNotFoundException, BindException { if (bindingResult.hasErrors()) { throw new BindException(bindingResult); } Project project = projectQueryService.findBy(new ProjectId(id)); project = projectCommandService.addStakeholder(new ProjectId(id), new Stakeholder(project.getTenantId(), pod.getName(), StakeholderType.INTERNAL, pod.getRole(), StakeholderClassification.NEUTRAL)); return new ResponseEntity<>(projectResourceAssembler.toResource(project), HttpStatus.OK); }