Search in sources :

Example 6 with NotFoundException

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");
    }
}
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

NotFoundException (org.c4sg.exception.NotFoundException)6 BadRequestException (org.c4sg.exception.BadRequestException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)2 UserOrganizationException (org.c4sg.exception.UserOrganizationException)2 UserProjectException (org.c4sg.exception.UserProjectException)2 CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 IOException (java.io.IOException)1 CreateOrganizationDTO (org.c4sg.dto.CreateOrganizationDTO)1 CreateUserDTO (org.c4sg.dto.CreateUserDTO)1 OrganizationDTO (org.c4sg.dto.OrganizationDTO)1 UserDTO (org.c4sg.dto.UserDTO)1 Badge (org.c4sg.entity.Badge)1 User (org.c4sg.entity.User)1 ProjectServiceException (org.c4sg.exception.ProjectServiceException)1 UserServiceException (org.c4sg.exception.UserServiceException)1 GeoCodeUtil (org.c4sg.util.GeoCodeUtil)1