use of org.springframework.web.bind.annotation.CrossOrigin 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) {
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