diff --git a/src/main/java/org/openlmis/fulfillment/web/OrderController.java b/src/main/java/org/openlmis/fulfillment/web/OrderController.java index 31d3c9c6..b4b2b24d 100644 --- a/src/main/java/org/openlmis/fulfillment/web/OrderController.java +++ b/src/main/java/org/openlmis/fulfillment/web/OrderController.java @@ -59,6 +59,7 @@ import org.openlmis.fulfillment.util.FacilityTypeHelper; import org.openlmis.fulfillment.web.util.BasicOrderDto; import org.openlmis.fulfillment.web.util.BasicOrderDtoBuilder; +import org.openlmis.fulfillment.web.util.IdsDto; import org.openlmis.fulfillment.web.util.OrderDto; import org.openlmis.fulfillment.web.util.OrderDtoBuilder; import org.openlmis.fulfillment.web.util.OrderReportDto; @@ -511,12 +512,13 @@ public ResultDto retryOrderTransfer(@PathVariable("id") UUID id) { /** * Delete multiple orders with status CREATING. * - * @param ids ids of orders to be deleted, should not be empty + * @param idsDto ids of orders to be deleted, should not be empty */ @RequestMapping(value = "/orders", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) - public void deleteMultipleOrders(@RequestBody List ids) { + public void deleteMultipleOrders(@RequestBody IdsDto idsDto) { + List ids = idsDto.getIds(); if (CollectionUtils.isEmpty(ids)) { XLOGGER.info("Nothing to delete"); throw new ValidationException("no ids given"); diff --git a/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java new file mode 100644 index 00000000..18b1122e --- /dev/null +++ b/src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java @@ -0,0 +1,12 @@ +package org.openlmis.fulfillment.web.util; + +import java.util.List; +import java.util.UUID; +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class IdsDto { + private List ids; +} diff --git a/src/main/resources/api-definition.yaml b/src/main/resources/api-definition.yaml index dd7db83f..42ca9415 100644 --- a/src/main/resources/api-definition.yaml +++ b/src/main/resources/api-definition.yaml @@ -100,7 +100,7 @@ schemas: "items": { "type": "object", "$ref": "schemas/auditLogEntry.json" } } - orderStatsData: !include schemas/orderStatsData.json - + - idsDto: !include schemas/idsDto.json traits: - secured: queryParameters: @@ -369,10 +369,10 @@ resourceTypes: schema: localizedMessage delete: is: [ secured ] - description: Removes many orders by id. This endpoint requires ORDERE_DELETE right. + description: Removes many orders by id. This endpoint requires ORDERS_DELETE right. body: application/json: - schema: uuidArray + schema: idsDto responses: "204": headers: diff --git a/src/main/resources/schemas/idsDto.json b/src/main/resources/schemas/idsDto.json new file mode 100644 index 00000000..1b010d58 --- /dev/null +++ b/src/main/resources/schemas/idsDto.json @@ -0,0 +1,16 @@ +{ + "type": "object", + "$schema": "http://json-schema.org/draft-04/schema", + "title": "IdsDto", + "description": "uuids container dto", + "properties": { + "ids": { + "title": "ids", + "type": "array", + "items": { + "type": "string", + "title": "id" + } + } + } +} diff --git a/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java b/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java index 0b44761f..bfddddbb 100644 --- a/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java +++ b/src/test/java/org/openlmis/fulfillment/web/OrderControllerTest.java @@ -56,6 +56,7 @@ import org.openlmis.fulfillment.testutils.UpdateDetailsDataBuilder; import org.openlmis.fulfillment.util.AuthenticationHelper; import org.openlmis.fulfillment.util.FacilityTypeHelper; +import org.openlmis.fulfillment.web.util.IdsDto; import org.openlmis.fulfillment.web.util.OrderDto; import org.openlmis.fulfillment.web.util.OrderDtoBuilder; import org.openlmis.fulfillment.web.validator.OrderValidator; @@ -186,6 +187,8 @@ public void shouldDeleteMultipleOrders() { ids.add(order.getId()); ids.add(orderTwo.getId()); + IdsDto idsDto = new IdsDto(ids); + List orders = new ArrayList(); orders.add(order); orders.add(orderTwo); @@ -196,7 +199,7 @@ public void shouldDeleteMultipleOrders() { receivingIds.add(orderTwo.getReceivingFacilityId()); //when - orderController.deleteMultipleOrders(ids); + orderController.deleteMultipleOrders(idsDto); //then verify(orderRepository).findByIdInAndStatus(ids, OrderStatus.CREATING.name());