Search in sources :

Example 6 with CrossOrigin

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");
    }
}
Also used : UserOrganizationException(org.c4sg.exception.UserOrganizationException) NotFoundException(org.c4sg.exception.NotFoundException) URI(java.net.URI) CrossOrigin(org.springframework.web.bind.annotation.CrossOrigin) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)6 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 IOException (java.io.IOException)3 NotFoundException (org.c4sg.exception.NotFoundException)3 UserOrganizationException (org.c4sg.exception.UserOrganizationException)3 ApiResponses (io.swagger.annotations.ApiResponses)2 HashMap (java.util.HashMap)2 CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)2 OrganizationDTO (org.c4sg.dto.OrganizationDTO)2 UserProjectException (org.c4sg.exception.UserProjectException)2 RequestMethod (org.springframework.web.bind.annotation.RequestMethod)2 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)2 HandlerMethod (org.springframework.web.method.HandlerMethod)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 URI (java.net.URI)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1