SHARE
TWEET

Untitled

a guest Jun 24th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public Mono<Void> deleteImage(String fileId) {
  2.     return Mono.fromRunnable(() -> {
  3.         imageRepository.findById(fileId)
  4.                 .map(image -> {
  5.                     Mono<Void> deleteFile = Mono.fromRunnable(() -> {
  6.                         try {
  7.                             Files.deleteIfExists(Paths.get(UPLOAD_ROOT, image.getId() + "-" + image.getName()));
  8.                         } catch (IOException e) {
  9.                             throw new RuntimeException(e);
  10.                         }
  11.                     });
  12.                     Mono<Void> deleteRecord = Mono.fromRunnable(() -> {
  13.                         imageRepository.delete(image);
  14.                     });
  15.                     return Mono.when(deleteFile, deleteRecord).then();
  16.                 });
  17.     }).then();
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top