Search in sources :

Example 1 with UserProjectException

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");
        }
    }
}
Also used : UserProject(org.c4sg.entity.UserProject) UserProjectException(org.c4sg.exception.UserProjectException)

Example 2 with UserProjectException

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;
    }
}
Also used : NotFoundException(org.c4sg.exception.NotFoundException) BadRequestException(org.c4sg.exception.BadRequestException) URI(java.net.URI) UserProjectException(org.c4sg.exception.UserProjectException)

Example 3 with UserProjectException

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");
        }
    }
}
Also used : UserProject(org.c4sg.entity.UserProject) UserProjectException(org.c4sg.exception.UserProjectException)

Aggregations

UserProjectException (org.c4sg.exception.UserProjectException)3 UserProject (org.c4sg.entity.UserProject)2 URI (java.net.URI)1 BadRequestException (org.c4sg.exception.BadRequestException)1 NotFoundException (org.c4sg.exception.NotFoundException)1