use of org.c4sg.exception.NotFoundException in project c4sg-services by Code4SocialGood.
the class OrganizationController method createUserOrganization.
@CrossOrigin
@RequestMapping(value = "/{id}/users/{userId}", method = RequestMethod.POST)
@ApiOperation(value = "Create a relation between user and organization")
@ApiResponses(value = { @ApiResponse(code = 404, message = "ID of organization or user invalid") })
public // TODO: Replace explicit user{id} with AuthN user id.
ResponseEntity<?> createUserOrganization(@ApiParam(value = "ID of user", required = true) @PathVariable("userId") Integer userId, @ApiParam(value = "ID of organization", required = true) @PathVariable("id") Integer organizationId) {
System.out.println("************** OrganizationController.createUserOrganization()" + ": userId=" + userId + "; organizationId=" + organizationId + " **************");
try {
organizationService.saveUserOrganization(userId, organizationId);
URI location = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}/users/{userId}").buildAndExpand(organizationId, userId).toUri();
return ResponseEntity.created(location).build();
} catch (NullPointerException | UserOrganizationException e) {
throw new NotFoundException("ID of organization or user invalid, or relationship already exist");
}
}
Aggregations