Skip to content

Commit

Permalink
Add duplication endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Ayoub LABIDI <ayoub.labidi@protonmail.com>
  • Loading branch information
ayolab committed Dec 26, 2023
1 parent 193e1b9 commit 5eb78ef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class LoadFlowParametersController {
@Autowired
private LoadFlowParametersService parametersService;

@PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(value = "", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Create parameters")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "parameters were created")})
Expand All @@ -42,6 +42,15 @@ public ResponseEntity<UUID> createParameters(
return ResponseEntity.ok().body(parametersService.createParameters(parametersInfos));
}

@PostMapping(value = "")
@Operation(summary = "Duplicate parameters")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "parameters were duplicated")})
public ResponseEntity<UUID> createParameters(
@RequestParam("duplicateFrom") UUID sourceParametersUuid) {
return ResponseEntity.ok().body(parametersService.duplicateParameters(sourceParametersUuid));
}

@GetMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get parameters")
@ApiResponses(value = {
Expand All @@ -61,7 +70,7 @@ public ResponseEntity<List<LoadFlowParametersInfos>> getAllParameters() {
return ResponseEntity.ok().body(parametersService.getAllParameters());
}

@PutMapping(value = "/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PutMapping(value = "/{uuid}", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Update parameters")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "parameters were updated")})
public ResponseEntity<Void> updateParameters(
Expand All @@ -71,7 +80,7 @@ public ResponseEntity<Void> updateParameters(
return ResponseEntity.ok().build();
}

@DeleteMapping(value = "/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)
@DeleteMapping(value = "/{uuid}")
@Operation(summary = "Delete parameters")
@ApiResponse(responseCode = "200", description = "parameters were deleted")
public ResponseEntity<Void> deleteParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.Map;

/**
* @author Ayoub LABIDI <ayoub.labidi at rte-france.com>
* @author David Braquart <david.braquart@rte-france.com>
*/
@Getter
@NoArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,8 @@ public LoadFlowParametersValues toLoadFlowParametersValues(String provider) {
LoadFlowSpecificParameterEntity::getValue)))
.build();
}

public LoadFlowParametersEntity copy() {
return toLoadFlowParametersInfos().toEntity();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,11 @@ public void updateParameters(UUID parametersUuid, LoadFlowParametersInfos parame
public void deleteParameters(UUID parametersUuid) {
loadFlowParametersRepository.deleteById(parametersUuid);
}

@Transactional
public UUID duplicateParameters(UUID sourceParametersUuid) {
LoadFlowParametersEntity sourceParameters = loadFlowParametersRepository.findById(sourceParametersUuid).orElseThrow();
LoadFlowParametersEntity duplicatedParameters = sourceParameters.copy();
return loadFlowParametersRepository.save(duplicatedParameters).toLoadFlowParametersInfos().getUuid();
}
}

0 comments on commit 5eb78ef

Please sign in to comment.