use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.
the class ProjectController method giveBadge.
// TODO: Replace explicit user{id} with AuthN user id.
@CrossOrigin
@RequestMapping(value = "/{id}/users/{userId}/badge", method = RequestMethod.POST)
@ApiOperation(value = "Give out badge for a volunteer")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of project or user invalid") })
public Badge giveBadge(@ApiParam(value = "ID of user", required = true) @PathVariable("userId") Integer userId, @ApiParam(value = "ID of project", required = true) @PathVariable("id") Integer projectId) {
System.out.println("************** ProjectController.giveBadge()" + ": userId=" + userId + "; projectId=" + projectId + " **************");
Badge badge = null;
try {
badge = badgeService.saveBadge(userId, projectId);
} catch (NullPointerException e) {
throw new NotFoundException("ID of project or user invalid");
} catch (Exception e) {
throw e;
}
return badge;
}
use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.
the class OrganizationController method getOrganizationsByUser.
@CrossOrigin
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
@ApiOperation(value = "Find organizations by user id", notes = "Returns a collection of organizations")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of user invalid") })
public List<OrganizationDTO> getOrganizationsByUser(@ApiParam(value = "userId of organizations to return", required = true) @PathVariable("id") Integer id) {
System.out.println("************** OrganizationController.getOrganizationsByUser()" + ": id=" + id + " **************");
List<OrganizationDTO> organizations = null;
try {
organizations = organizationService.findByUser(id);
} catch (Exception e) {
throw new NotFoundException("ID of user invalid");
}
return organizations;
}
use of org.c4sg.exception.NotFoundException 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.NotFoundException in project c4sg-services by Code4SocialGood.
the class UserController method createUser.
@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "Add a new user")
public UserDTO createUser(@ApiParam(value = "User object to return", required = true) @RequestBody CreateUserDTO createUserDTO) {
//calculate lat and long
try {
UserDTO userDTO = userService.createUser(createUserDTO);
GeoCodeUtil geoCodeUtil = new GeoCodeUtil(userDTO);
Map<String, BigDecimal> geoCode = geoCodeUtil.getGeoCode();
userDTO.setLatitude(geoCode.get("lat"));
userDTO.setLongitude(geoCode.get("lon"));
return userService.saveUser(userDTO);
} catch (Exception e) {
throw new NotFoundException("Error getting geocode");
}
}
use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.
the class UserServiceImpl method saveUser.
@Override
public UserDTO saveUser(UserDTO userDTO) {
User user = userMapper.getUserEntityFromDto(userDTO);
try {
Map<String, BigDecimal> geoCode = geocodeService.getGeoCode(user.getState(), user.getCountry());
user.setLatitude(geoCode.get("lat"));
user.setLongitude(geoCode.get("lng"));
} catch (Exception e) {
throw new NotFoundException("Error getting geocode");
}
return userMapper.getUserDtoFromEntity(userDAO.save(user));
}
Aggregations