@RequestMapping(value = "status/update", method = RequestMethod.POST) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_INVENTORY')") public ResponseEntity<OpenLmisResponse> updateStatus( @RequestBody EquipmentInventory inventory, HttpServletRequest request) { ResponseEntity<OpenLmisResponse> response; Long userId = loggedInUserId(request); inventory.setModifiedBy(userId); service.updateStatus(inventory); service.updateNonFunctionalEquipments(); response = OpenLmisResponse.success(messageService.message("message.equipment.inventory.saved")); response.getBody().addData(INVENTORY, inventory); return response; }
@Test public void shouldGetInventoryById() throws Exception { EquipmentInventory inventory = new EquipmentInventory(); when(service.getInventoryById(1L)).thenReturn(inventory); ResponseEntity<OpenLmisResponse> response = controller.getInventory(1L); assertThat(inventory, is(response.getBody().getData().get("inventory"))); }
@RequestMapping(value = "list", method = RequestMethod.GET) public ResponseEntity<OpenLmisResponse> getInventory( @RequestParam("typeId") Long typeId, @RequestParam("programId") Long programId, @RequestParam("equipmentTypeId") Long equipmentTypeId, @RequestParam(value = "page", defaultValue = "1") Integer page, @Value("${search.page.size}") String limit, HttpServletRequest request) { Long userId = loggedInUserId(request); Pagination pagination = new Pagination(page, parseInt(limit)); pagination.setTotalRecords( service.getInventoryCount(userId, typeId, programId, equipmentTypeId)); List<EquipmentInventory> inventory = service.getInventory(userId, typeId, programId, equipmentTypeId, pagination); ResponseEntity<OpenLmisResponse> response = OpenLmisResponse.response(INVENTORY, inventory); response.getBody().addData(PAGINATION, pagination); return response; }
@Test public void shouldGetInventory() throws Exception { List<EquipmentInventory> inventories = new ArrayList<>(); Pagination page = new Pagination(1, 2); when(service.getInventory(1L, 1L, 1L, 1L, page)).thenReturn(inventories); ResponseEntity<OpenLmisResponse> response = controller.getInventory(1L, 1L, 1L, 1, "2", request); assertThat(inventories, is(response.getBody().getData().get("inventory"))); }
@RequestMapping(value = "by-id", method = RequestMethod.GET) @PreAuthorize("@permissionEvaluator.hasPermission(principal,'MANAGE_EQUIPMENT_INVENTORY')") public ResponseEntity<OpenLmisResponse> getInventory(@RequestParam("id") Long id) { return OpenLmisResponse.response(INVENTORY, service.getInventoryById(id)); }