/** GET /roles -> get all the roles. */ @RequestMapping( value = "/roles", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<List<Role>> getAllRoles(Pageable pageable) throws URISyntaxException { Page<Role> page = roleRepository.findAll(pageable); HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/roles"); return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK); }
/** GET /roles/:id -> get the "id" role. */ @RequestMapping( value = "/roles/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Role> getRole(@PathVariable Long id) { log.debug("REST request to get Role : {}", id); return Optional.ofNullable(roleRepository.findOne(id)) .map(role -> new ResponseEntity<>(role, HttpStatus.OK)) .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); }
/** DELETE /roles/:id -> delete the "id" role. */ @RequestMapping( value = "/roles/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Void> deleteRole(@PathVariable Long id) { log.debug("REST request to delete Role : {}", id); roleRepository.delete(id); roleSearchRepository.delete(id); return ResponseEntity.ok() .headers(HeaderUtil.createEntityDeletionAlert("role", id.toString())) .build(); }
/** PUT /roles -> Updates an existing role. */ @RequestMapping( value = "/roles", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Role> updateRole(@Valid @RequestBody Role role) throws URISyntaxException { log.debug("REST request to update Role : {}", role); if (role.getId() == null) { return createRole(role); } Role result = roleRepository.save(role); roleSearchRepository.save(role); return ResponseEntity.ok() .headers(HeaderUtil.createEntityUpdateAlert("role", role.getId().toString())) .body(result); }
/** POST /roles -> Create a new role. */ @RequestMapping( value = "/roles", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Role> createRole(@Valid @RequestBody Role role) throws URISyntaxException { log.debug("REST request to save Role : {}", role); if (role.getId() != null) { return ResponseEntity.badRequest() .header("Failure", "A new role cannot already have an ID") .body(null); } Role result = roleRepository.save(role); roleSearchRepository.save(result); return ResponseEntity.created(new URI("/api/roles/" + result.getId())) .headers(HeaderUtil.createEntityCreationAlert("role", result.getId().toString())) .body(result); }