package com.rshk.demo.controllers; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import com.rshk.demo.beans.Customer; import com.rshk.demo.beans.CustomerGetRespData; import com.rshk.demo.beans.CustomerListData; import com.rshk.demo.services.CustomerService; @RestController @RequestMapping("/api-customers") public class CustomerController { @Autowired private CustomerService customerService; @RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity getCustomerList() { try { ResponseEntity response = null; return new ResponseEntity(customerService.getCustomers(), HttpStatus.OK); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity( new com.rshk.demo.beans.Error("FTL_PF_1231", e.getMessage()), HttpStatus.UNPROCESSABLE_ENTITY); } } @RequestMapping(value = "/{document}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity get(@PathVariable String id) { try { ResponseEntity response = null; return new ResponseEntity(customerService.get(id), HttpStatus.OK); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(new Error(), HttpStatus.UNPROCESSABLE_ENTITY); } } @RequestMapping(value = "/save", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity get(@RequestBody Customer customer) { try { ResponseEntity response = null; return new ResponseEntity(customerService.insert(customer), HttpStatus.OK); } catch (Exception e) { e.printStackTrace(); return new ResponseEntity(new Error(), HttpStatus.UNPROCESSABLE_ENTITY); } } }