Skip to content

Commit

Permalink
Deliverable Details Update API
Browse files Browse the repository at this point in the history
  • Loading branch information
Sowmya-Raghuram committed May 29, 2024
1 parent 8e95301 commit d317c1e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import com.sunbird.serve.need.models.Need.NeedDeliverable;
import com.sunbird.serve.need.models.Need.InputParameters;
import com.sunbird.serve.need.models.enums.NeedDeliverableStatus;
import com.sunbird.serve.need.models.request.NeedDeliverableRequest;
import com.sunbird.serve.need.models.request.DeliverableDetailsRequest;
import com.sunbird.serve.need.models.response.NeedDeliverableResponse;
import org.springframework.http.HttpStatus;
import java.util.List;
Expand Down Expand Up @@ -89,4 +91,21 @@ public ResponseEntity<NeedDeliverable> updateNeedDeliverable(
return ResponseEntity.ok(updatedNeedDeliverable);
}

//Update Need Deliverable Details
@Operation(summary = "Update a Need Deliverable Details with appropritate values", description = "Update an exsisting need deliverable details")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Successfully Updated Need Deliverable Details", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)),
@ApiResponse(responseCode = "400", description = "Bad Input"),
@ApiResponse(responseCode = "500", description = "Server Error")}
)
@PutMapping("/deliverable-details/update/{needDeliverableId}")
public ResponseEntity<List<InputParameters>> updateDeliverableDetails(
@PathVariable String needDeliverableId,
@RequestBody DeliverableDetailsRequest request,
@RequestHeader Map<String, String> headers) {

List<InputParameters> updatedInputParameters = needDeliverableService.updateInputParameters(needDeliverableId, request, headers);
return ResponseEntity.ok(updatedInputParameters);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sunbird.serve.need.models.Need.NeedDeliverable;
import com.sunbird.serve.need.models.Need.InputParameters;
import com.sunbird.serve.need.models.request.NeedDeliverableRequest;
import com.sunbird.serve.need.models.request.DeliverableDetailsRequest;
import com.sunbird.serve.need.models.response.NeedDeliverableResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -69,4 +70,23 @@ public NeedDeliverable updateNeedDeliverable(UUID needDeliverableId, NeedDeliver
return needDeliverableRepository.save(existingNeedDeliverable);
}

public List<InputParameters> updateInputParameters(String needDeliverableId, DeliverableDetailsRequest request, Map<String, String> headers) {
// Check if the need with the given ID exists
List<InputParameters> existingInputParameters = inputParametersRepository.findByNeedDeliverableId(needDeliverableId);

if (existingInputParameters != null) {
for (InputParameters parameter : existingInputParameters) {
parameter.setNeedDeliverableId(request.getNeedDeliverableId());
parameter.setInputUrl(request.getInputUrl());
parameter.setSoftwarePlatform(request.getSoftwarePlatform());
parameter.setStartTime(request.getStartTime());
parameter.setEndTime(request.getEndTime());
}


}
// Save the updated need
return inputParametersRepository.saveAll(existingInputParameters);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
@NoArgsConstructor
@AllArgsConstructor
public class DeliverableDetailsRequest {
private String needId;
private String needDeliverableId;
private String inputUrl;
private SoftwarePlatform softwarePlatform;
private Instant startTime;
private Instant endTime;
private Instant deliverableDate;
}

0 comments on commit d317c1e

Please sign in to comment.