@RequestMapping(value="/dept", method = RequestMethod.GET) public ResponseEntity<List<DeptJson>> listAllDepts() { Iterable<Department> depts = deptRepo.findAll(); List<DeptJson> deptJsons = new ArrayList<DeptJson>(); if(depts==null){ return new ResponseEntity<List<DeptJson>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND } else { for (Department dept: depts) { DeptJson deptJson = new DeptJson(dept, dept.getEmps()); deptJsons.add(deptJson); } return new ResponseEntity<List<DeptJson>>(deptJsons, HttpStatus.OK); } } //-------------------Retrieve One Departments by Dept Id-------------------
@RequestMapping(value="/dept", method = RequestMethod.GET) public ResponseEntity<List<DeptJson>> listAllDepts() { Iterable<Department> depts = deptRepo.findAll(); List<DeptJson> deptJsons = new ArrayList<DeptJson>(); if(depts==null){ return new ResponseEntity<List<DeptJson>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND } else { for (Department dept: depts) { DeptJson deptJson = new DeptJson(dept, dept.getEmps()); deptJsons.add(deptJson); } return new ResponseEntity<List<DeptJson>>(deptJsons, HttpStatus.OK); } } //-------------------Retrieve One Departments by Dept Id-------------------
@RequestMapping(value="/dept", method = RequestMethod.GET) public ResponseEntity<List<DeptJson>> listAllDepts() { Iterable<Department> depts = deptRepo.findAll(); List<DeptJson> deptJsons = new ArrayList<DeptJson>(); if(depts==null){ return new ResponseEntity<List<DeptJson>>(HttpStatus.NO_CONTENT);//You many decide to return HttpStatus.NOT_FOUND } else { for (Department dept: depts) { DeptJson deptJson = new DeptJson(dept, dept.getEmps()); deptJsons.add(deptJson); } return new ResponseEntity<List<DeptJson>>(deptJsons, HttpStatus.OK); } } //-------------------Retrieve One Departments by Dept Id-------------------
@RequestMapping(value = "/dept/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<DeptJson> getUser(@PathVariable("id") long id) { System.out.println("Fetching User with id " + id); Department dept = deptRepo.findOne(id); if (dept == null) { System.out.println("dept with id " + id + " not found"); return new ResponseEntity<DeptJson>(HttpStatus.NOT_FOUND); } else { System.out.println(dept.getDeptName()); System.out.println(dept.getEmps().size()); DeptJson deptInfo = new DeptJson(dept, dept.getEmps()); return new ResponseEntity<DeptJson>(deptInfo, HttpStatus.OK); } } //-------------------Create new Department---------------------------------
@RequestMapping(value = "/dept/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<DeptJson> getUser(@PathVariable("id") long id) { System.out.println("Fetching Dept with id " + id); Department dept = deptRepo.findOne(id); if (dept == null) { System.out.println("dept with id " + id + " not found"); return new ResponseEntity<DeptJson>(HttpStatus.NOT_FOUND); } else { System.out.println(dept.getDeptName()); System.out.println(dept.getEmps().size()); DeptJson deptInfo = new DeptJson(dept, dept.getEmps()); return new ResponseEntity<DeptJson>(deptInfo, HttpStatus.OK); } } //-------------------Create new Department---------------------------------
@RequestMapping(value = "/dept/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<DeptJson> getUser(@PathVariable("id") long id) { System.out.println("Fetching User with id " + id); Department dept = deptRepo.findOne(id); if (dept == null) { System.out.println("dept with id " + id + " not found"); return new ResponseEntity<DeptJson>(HttpStatus.NOT_FOUND); } else { System.out.println(dept.getDeptName()); System.out.println(dept.getEmps().size()); DeptJson deptInfo = new DeptJson(dept, dept.getEmps()); return new ResponseEntity<DeptJson>(deptInfo, HttpStatus.OK); } } //-------------------Create new Department---------------------------------