diff --git a/src/main/java/com/sunbird/serve/need/DeliverableService/controllers/NeedDeliverableController.java b/src/main/java/com/sunbird/serve/need/DeliverableService/controllers/NeedDeliverableController.java index cc30158..00ab98d 100644 --- a/src/main/java/com/sunbird/serve/need/DeliverableService/controllers/NeedDeliverableController.java +++ b/src/main/java/com/sunbird/serve/need/DeliverableService/controllers/NeedDeliverableController.java @@ -110,6 +110,23 @@ public ResponseEntity> updateDeliverableDetails( return ResponseEntity.ok(updatedInputParameters); } + //Update Need Deliverable Details + @Operation(summary = "Update all Need Deliverables with appropritate values", description = "Update all need deliverable details") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Successfully Updated all Need Deliverable Details", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), + @ApiResponse(responseCode = "400", description = "Bad Input"), + @ApiResponse(responseCode = "500", description = "Server Error")} + ) + @PutMapping("/all-deliverable-details/update/{needPlanId}") + public ResponseEntity> updateNeedDeliverableDetails( + @PathVariable String needPlanId, + @RequestBody DeliverableDetailsRequest request, + @RequestHeader Map headers) { + + List updatedNeedDeliverables = needDeliverableService.updateNeedDeliverables(needPlanId, request, headers); + return ResponseEntity.ok(updatedNeedDeliverables); + } + //Create Output Parameters for Deliverable Details @Operation(summary = "Create Output Parameters", description = "Create Output Parameters for Deliverable Details") @ApiResponses(value = { diff --git a/src/main/java/com/sunbird/serve/need/DeliverableService/services/NeedDeliverableService.java b/src/main/java/com/sunbird/serve/need/DeliverableService/services/NeedDeliverableService.java index 745b86f..919dfed 100644 --- a/src/main/java/com/sunbird/serve/need/DeliverableService/services/NeedDeliverableService.java +++ b/src/main/java/com/sunbird/serve/need/DeliverableService/services/NeedDeliverableService.java @@ -110,13 +110,40 @@ public NeedDeliverable updateNeedDeliverable(UUID needDeliverableId, NeedDeliver return updatedNeedDeliverable; } + + public List updateNeedDeliverables(String needPlanId, DeliverableDetailsRequest request, Map headers) { + // Fetch all deliverables based on needPlanId + List needDeliverableList = needDeliverableRepository.findByNeedPlanId(needPlanId); + + List updatedDeliverables = new ArrayList<>(); + + for (NeedDeliverable needDeliverables : needDeliverableList) { + // new request object with details from the need deliverable + DeliverableDetailsRequest newRequest = DeliverableDetailsRequest.builder() + .inputUrl(request.getInputUrl()) + .softwarePlatform(request.getSoftwarePlatform()) + .startTime(request.getStartTime()) + .endTime(request.getEndTime()) + .build(); + + // Call updateInputParameters method for each deliverable + List updatedInputParameters = updateInputParameters(needDeliverables.getId().toString(), newRequest, headers); + + // Assuming updateInputParameters updates the needDeliverable and saves it + updatedDeliverables.add(needDeliverables); + } + return updatedDeliverables; +} + + + public List updateInputParameters(String needDeliverableId, DeliverableDetailsRequest request, Map headers) { // Check if the need with the given ID exists List existingInputParameters = inputParametersRepository.findByNeedDeliverableId(needDeliverableId); if (existingInputParameters != null) { for (InputParameters parameter : existingInputParameters) { - parameter.setNeedDeliverableId(request.getNeedDeliverableId()); + parameter.setNeedDeliverableId(needDeliverableId); parameter.setInputUrl(request.getInputUrl()); parameter.setSoftwarePlatform(request.getSoftwarePlatform()); parameter.setStartTime(request.getStartTime()); diff --git a/src/main/java/com/sunbird/serve/need/models/request/DeliverableDetailsRequest.java b/src/main/java/com/sunbird/serve/need/models/request/DeliverableDetailsRequest.java index d1a1368..2649132 100644 --- a/src/main/java/com/sunbird/serve/need/models/request/DeliverableDetailsRequest.java +++ b/src/main/java/com/sunbird/serve/need/models/request/DeliverableDetailsRequest.java @@ -16,7 +16,6 @@ @NoArgsConstructor @AllArgsConstructor public class DeliverableDetailsRequest { - private String needDeliverableId; private String inputUrl; private SoftwarePlatform softwarePlatform; private Instant startTime;