Skip to content

Commit

Permalink
FIX : change delete logic for cascading #4
Browse files Browse the repository at this point in the history
  • Loading branch information
stephano-tri committed Feb 22, 2024
1 parent 623bfba commit 0d07ecf
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/kotlin/eom/improve/kafkaboot/service/FilmService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FilmService(
fun deleteFilm(filmId : Int) : Mono<Void> {
// need to implement cascade delete(maybe soft) for table data that set foreign key
return filmRepository.findById(filmId)
.switchIfEmpty(Mono.error(RuntimeException("Not registered film")))
.switchIfEmpty(RuntimeException("Not registered film").toMono())
.flatMap { filmEn ->
inventoryRepository.findAllByFilmId(filmEn.filmId)
.flatMap { inventoryEn ->
Expand All @@ -49,9 +49,16 @@ class FilmService(
}
.flatMap { rentalEn ->
rentalRepository.deleteByRentalId(rentalEn.rentalId)
}
}.then()
}.then(inventoryEn.toMono())
}
.flatMap { inventoryEn ->
println(inventoryEn.inventoryId)
inventoryRepository.deleteByInventoryId(inventoryEn.inventoryId)
}
.then(filmEn.toMono())
}
.flatMap { filmEn ->
filmRepository.deleteByFilmId(filmEn.filmId)
}

}
}

0 comments on commit 0d07ecf

Please sign in to comment.