Skip to content

Commit

Permalink
OAM-200: Added container for request body due to problems with array …
Browse files Browse the repository at this point in the history
…in body.
  • Loading branch information
tsznaj committed Jun 19, 2024
1 parent 1bd60f6 commit 8a30639
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -511,12 +512,13 @@ public ResultDto<Boolean> 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<UUID> ids) {
public void deleteMultipleOrders(@RequestBody IdsDto idsDto) {

List<UUID> ids = idsDto.getIds();
if (CollectionUtils.isEmpty(ids)) {
XLOGGER.info("Nothing to delete");
throw new ValidationException("no ids given");
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/openlmis/fulfillment/web/util/IdsDto.java
Original file line number Diff line number Diff line change
@@ -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<UUID> ids;
}
6 changes: 3 additions & 3 deletions src/main/resources/api-definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/schemas/idsDto.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -186,6 +187,8 @@ public void shouldDeleteMultipleOrders() {
ids.add(order.getId());
ids.add(orderTwo.getId());

IdsDto idsDto = new IdsDto(ids);

List<Order> orders = new ArrayList();
orders.add(order);
orders.add(orderTwo);
Expand All @@ -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());
Expand Down

0 comments on commit 8a30639

Please sign in to comment.