@RequestMapping(method = RequestMethod.DELETE, value = "/delete/{id}") public void removeEarning(@PathVariable Long id, HttpServletResponse response) throws JsonGenerationException, JsonMappingException, IOException { log.info("Delete earnings..."); boolean result = earningsService.removeEarning(id); response.setContentType(MediaType.APPLICATION_JSON_VALUE); new ObjectMapper().writeValue(response.getOutputStream(), result); }
@RequestMapping(method = RequestMethod.PUT, value = "/add/{label}/{amount}") public void addEarning( @PathVariable String label, @PathVariable int amount, HttpServletResponse response) throws JsonGenerationException, JsonMappingException, IOException { log.info("Add new earnings..."); long id = earningsService.addEarning(label, amount, null); response.setContentType(MediaType.APPLICATION_JSON_VALUE); new ObjectMapper().writeValue(response.getOutputStream(), id); }
@RequestMapping(method = RequestMethod.GET, value = "/all") public void getAllEarnings(HttpServletRequest request, HttpServletResponse response) throws JsonGenerationException, JsonMappingException, IOException { log.info("Retrieving earnings..."); List<Earning> l = earningsService.getEarnings(); log.info("Write JSON in the output stream of the servlet"); response.setContentType(MediaType.APPLICATION_JSON_VALUE); new ObjectMapper().writeValue(response.getOutputStream(), l); }