/** * Endpoint for retrieving metadata information for suggested names * * @return a {@link ResponseEntity} with the response message */ @RequestMapping(value = "/meta", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Map<String, Object>> getSuggestedMetaData() { Map<String, Object> metaData = new HashMap<>(); metaData.put("totalSuggestedNames", suggestedNameRepository.count()); return new ResponseEntity<>(metaData, HttpStatus.OK); }
/** * Returns all the suggested names * @return a {@link ResponseEntity} with all suggested names */ @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public List<SuggestedName> getAllSuggestedNames() { return suggestedNameRepository.findAll(); }
/** * End point for deleting suggested name * @param id id of the suggested name to delete * @return */ @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) public ResponseEntity<Map<String, String>> deleteSuggestedName(@PathVariable Long id) { SuggestedName suggestedName = suggestedNameRepository.findOne(id); if (suggestedName != null) { suggestedNameRepository.delete(suggestedName); return new ResponseEntity<>(response("Suggested name with " + id + " successfully deleted"), HttpStatus.NO_CONTENT); } return new ResponseEntity<>(response("Suggested name with " + id + " not found as a suggested name"), HttpStatus.BAD_REQUEST); }
/** * End point for deleting all suggested name * * @return */ @RequestMapping(method = RequestMethod.DELETE) public ResponseEntity<Map<String, String>> deleteAllSuggestions() { suggestedNameRepository.deleteAll(); return new ResponseEntity<>(response("All suggested names has been deleted"), HttpStatus.OK); }
/** * End point for receiving suggested names into the database. The names * suggested won't be added to the main database or search index until * approved by admin of the system. * @param suggestedName the name suggested * @param bindingResult the {@link BindingResult} * @return {@link org.springframework.http.ResponseEntity} with message if successful or not */ @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Map<String, String>> suggestName(@Valid @RequestBody SuggestedName suggestedName, BindingResult bindingResult) { if (bindingResult.hasErrors()) { throw new GenericApiCallException(formatErrorMessage(bindingResult), HttpStatus.BAD_REQUEST); } suggestedNameRepository.save(suggestedName); return new ResponseEntity<>(response("Suggested Name successfully added"), HttpStatus.CREATED); }