Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
Signed-off-by: maissa SOUISSI <[email protected]>
  • Loading branch information
souissimai committed Sep 10, 2024
1 parent 67cb880 commit edd9215
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,8 @@ public ResponseEntity<Map<UUID, UUID>> duplicateModifications(@Parameter(descrip
@ApiResponse(responseCode = "200", description = "The network modifications were stashed")
public ResponseEntity<Void> stashNetworkModifications(
@Parameter(description = "Network modification UUIDs") @RequestParam("uuids") List<UUID> networkModificationUuids,
@Parameter(description = "Group UUID") @RequestParam("groupUuid") UUID groupUuid,
@Parameter(description = "stash or unstash network modifications") @RequestParam(name = "stashed", defaultValue = "true") Boolean stashed) {
if (Boolean.TRUE.equals(stashed)) {
networkModificationService.stashNetworkModifications(networkModificationUuids);
} else {
networkModificationService.restoreNetworkModifications(networkModificationUuids);
}
@Parameter(description = "stash or restore network modifications") @RequestParam(name = "stashed", defaultValue = "true") Boolean stashed) {
networkModificationService.stashNetworkModifications(networkModificationUuids, stashed);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,23 +388,12 @@ public List<ModificationInfos> getActiveModificationsInfos(@NonNull UUID groupUu
}

@Transactional
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids) {
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids, Boolean stashed) {
for (UUID modificationUuid : modificationUuids) {
ModificationEntity modificationEntity = this.modificationRepository
.findById(modificationUuid)
.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid)));
modificationEntity.setStashed(true);
this.modificationRepository.save(modificationEntity);
}
}

@Transactional
public void restoreNetworkModifications(@NonNull List<UUID> modificationUuids) {
for (UUID modificationUuid : modificationUuids) {
ModificationEntity modificationEntity = this.modificationRepository
.findById(modificationUuid)
.orElseThrow(() -> new NetworkModificationException(MODIFICATION_NOT_FOUND, String.format(MODIFICATION_NOT_FOUND_MESSAGE, modificationUuid)));
modificationEntity.setStashed(false);
modificationEntity.setStashed(stashed);
this.modificationRepository.save(modificationEntity);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,8 @@ public void updateNetworkModification(@NonNull UUID modificationUuid, @NonNull M
}

@Transactional
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids) {
networkModificationRepository.stashNetworkModifications(modificationUuids);
}

@Transactional
public void restoreNetworkModifications(@NonNull List<UUID> modificationUuids) {
networkModificationRepository.restoreNetworkModifications(modificationUuids);
public void stashNetworkModifications(@NonNull List<UUID> modificationUuids, boolean stashed) {
networkModificationRepository.stashNetworkModifications(modificationUuids, stashed);
}

// No transactional because we need to save modification in DB also in case of error
Expand Down

0 comments on commit edd9215

Please sign in to comment.