Skip to content

Commit

Permalink
draft getCompositeModification endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Mathieu DEHARBE <[email protected]>
  • Loading branch information
Mathieu-Deharbe committed Oct 8, 2024
1 parent ffd24f7 commit 190e807
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,19 @@ public ResponseEntity<UUID> createNetworkCompositeModification(@RequestBody List
return ResponseEntity.ok().body(networkModificationService.createNetworkCompositeModification(modificationUuids));
}

@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get the content of a composite modification via its id")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"),
@ApiResponse(responseCode = "404", description = "This composite modification does not exist")}
)
// TODO : renvoyer plutôt des métadonnées plutôt que des modifications complètes ?? (List<ModificationMetadata>) ?? => bof pas de name dedans !
public ResponseEntity<List<ModificationInfos>> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(networkModificationService.getCompositeModificationContentInfos(compositeModificationId)
);
}

@PostMapping(value = "/network-modifications", consumes = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Duplicate some modifications without group ownership")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The duplicated modifications uuids mapped with their source uuid")})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,11 @@ public List<ModificationInfos> getModificationsInfos(@NonNull List<UUID> uuids)
return uuids.stream().map(entities::get).filter(Objects::nonNull).map(this::getModificationInfos).toList();
}

/**
* @return the data from all the network modification contained in the composite modification sent as parameters
*/
@Transactional(readOnly = true)
public List<ModificationInfos> getCompositeModificationsInfos(@NonNull List<UUID> uuids) {
public List<ModificationInfos> getCompositeModificationsContentInfos(@NonNull List<UUID> uuids) {
List<ModificationInfos> entities = new ArrayList<>();
uuids.forEach(uuid -> {
List<UUID> foundEntities = modificationRepository.findModificationIdsByCompositeModificationId(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public List<ModificationInfos> getNetworkModifications(UUID groupUuid, boolean o
return getNetworkModifications(groupUuid, onlyMetadata, errorOnGroupNotFound, false);
}

@Transactional(readOnly = true)
// Need a transaction for collections lazy loading ==> TODO : this is copy pasted, is this true here ?
public List<ModificationInfos> getCompositeModificationContentInfos(UUID compositeModificationUuid) {
return networkModificationRepository.getCompositeModificationsContentInfos(List.of(compositeModificationUuid));
}

@Transactional(readOnly = true)
public ModificationInfos getNetworkModification(UUID networkModificationUuid) {
return networkModificationRepository.getModificationInfo(networkModificationUuid);
Expand Down Expand Up @@ -285,7 +291,7 @@ public Optional<NetworkModificationResult> duplicateModifications(UUID targetGro
public Optional<NetworkModificationResult> insertCompositeModifications(UUID targetGroupUuid,
UUID networkUuid, String variantId,
ReportInfos reportInfos, List<UUID> modificationsUuids) {
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsInfos(modificationsUuids);
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids);
networkModificationRepository.saveModificationInfos(targetGroupUuid, modificationInfos);
return applyModifications(networkUuid, variantId, reportInfos, modificationInfos);
}
Expand Down Expand Up @@ -328,7 +334,7 @@ public Optional<NetworkModificationResult> applyModificationsFromUuids(UUID netw
String variantId,
ReportInfos reportInfos,
List<UUID> modificationsUuids) {
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsInfos(modificationsUuids);
List<ModificationInfos> modificationInfos = networkModificationRepository.getCompositeModificationsContentInfos(modificationsUuids);
return applyModifications(networkUuid, variantId, reportInfos, modificationInfos);
}
}

0 comments on commit 190e807

Please sign in to comment.