use of org.c4sg.exception.UserProjectException in project c4sg-services by Code4SocialGood.
the class ProjectServiceImpl method isBookmarkPresent.
private void isBookmarkPresent(Integer userId, Integer projectId) {
List<UserProject> userProjects = userProjectDAO.findByUser_IdAndProject_IdAndStatus(userId, projectId, "B");
requireNonNull(userProjects, "Invalid operation");
for (UserProject userProject : userProjects) {
if (userProject.getStatus().equals("B")) {
throw new UserProjectException("Project is already bookmarked");
}
}
}
use of org.c4sg.exception.UserProjectException 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.UserProjectException in project c4sg-services by Code4SocialGood.
the class ProjectServiceImpl method isUserAppliedPresent.
private void isUserAppliedPresent(Integer userId, Integer projectId) throws UserProjectException {
List<UserProject> userProjects = userProjectDAO.findByUser_IdAndProject_IdAndStatus(userId, projectId, "A");
requireNonNull(userProjects, "Invalid operation");
for (UserProject userProject : userProjects) {
if (userProject.getStatus().equals("A")) {
throw new UserProjectException("Project is already applied for");
}
}
}
Aggregations