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.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("/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; List customerList = customerService.getCustomers(); return new ResponseEntity(new CustomerListData(customerList), 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; Customer customer = customerService.get(id); return new ResponseEntity(new CustomerGetRespData(customer), HttpStatus.OK); }catch(Exception e) { e.printStackTrace(); return new ResponseEntity(new Error(), HttpStatus.UNPROCESSABLE_ENTITY); } } }