use of org.c4sg.exception.BadRequestException in project c4sg-services by Code4SocialGood.
the class ProjectController method createUserProject.
@CrossOrigin
@RequestMapping(value = "/{id}/users/{userId}", method = RequestMethod.POST)
@ApiOperation(value = "Create a relation between user and project")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of project or user invalid") })
public //TODO: Replace explicit user{id} with AuthN user id.
ResponseEntity<?> createUserProject(@ApiParam(value = "ID of user", required = true) @PathVariable("userId") Integer userId, @ApiParam(value = "ID of project", required = true) @PathVariable("id") Integer projectId, @ApiParam(value = "User project status, A-Applied, B-Bookmarked", allowableValues = "A, B", required = true) @RequestParam("userProjectStatus") String userProjectStatus) {
try {
projectService.saveUserProject(userId, projectId, userProjectStatus);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}/users/{userId}").buildAndExpand(projectId, userId, userProjectStatus).toUri();
return ResponseEntity.created(location).build();
} catch (NullPointerException e) {
throw new NotFoundException("ID of project or user invalid");
} catch (UserProjectException | BadRequestException e) {
throw e;
}
}
use of org.c4sg.exception.BadRequestException in project c4sg-services by Code4SocialGood.
the class ProjectServiceImpl method saveUserProject.
@Override
public ProjectDTO saveUserProject(Integer userId, Integer projectId, String userProjectStatus) {
User user = userDAO.findById(userId);
requireNonNull(user, "Invalid User Id");
Project project = projectDAO.findById(projectId);
requireNonNull(project, "Invalid Project Id");
if (userProjectStatus == null || (!userProjectStatus.trim().equalsIgnoreCase("A") && !userProjectStatus.trim().equalsIgnoreCase("B"))) {
throw new BadRequestException("Invalid Project Status");
} else if (userProjectStatus.trim().equalsIgnoreCase("A")) {
isUserAppliedPresent(userId, projectId);
UserProject userProject = new UserProject();
userProject.setUser(user);
userProject.setProject(project);
userProject.setStatus("A");
apply(user, project);
userProjectDAO.save(userProject);
} else if (userProjectStatus.trim().equalsIgnoreCase("B")) {
isBookmarkPresent(userId, projectId);
UserProject userProject = new UserProject();
userProject.setUser(user);
userProject.setProject(project);
userProject.setStatus("B");
userProjectDAO.save(userProject);
}
return projectMapper.getProjectDtoFromEntity(project);
}
use of org.c4sg.exception.BadRequestException in project c4sg-services by Code4SocialGood.
the class ApplicationServiceImpl method validateApplication.
private void validateApplication(ApplicationDTO application) {
User user = userDAO.findById(application.getUserId());
requireNonNull(user, "Invalid User Id");
Project project = projectDAO.findById(application.getProjectId());
requireNonNull(project, "Invalid Project Id");
if (application.getStatus() == null || (!application.getStatus().equals("A") && !application.getStatus().equals("C") && !application.getStatus().equals("D"))) {
throw new BadRequestException("Invalid Project Status");
}
}
Aggregations