Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAM-200: Added container for request body due to problems with array … #33

Merged
merged 5 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 27 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,27 @@
/*
* This program is part of the OpenLMIS logistics management information system platform software.
* Copyright © 2017 VillageReach
*
* This program is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details. You should have received a copy of
* the GNU Affero General Public License along with this program. If not, see
* http://www.gnu.org/licenses.  For additional information contact [email protected].
*/

package org.openlmis.fulfillment.web.util;
tsznaj marked this conversation as resolved.
Show resolved Hide resolved

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);
tsznaj marked this conversation as resolved.
Show resolved Hide resolved

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
Loading