File tree Expand file tree Collapse file tree 4 files changed +18
-1
lines changed
src/main/kotlin/eom/improve/kafkaboot Expand file tree Collapse file tree 4 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -17,4 +17,7 @@ interface FilmController {
1717
1818 @PostMapping(" /save" )
1919 fun saveFilm (@Valid @RequestBody toBeSavedFilm : Film ) : Mono <Film >
20+
21+ @DeleteMapping(" /delete/{filmId}" )
22+ fun deleteFilm (@PathVariable filmId : Int ) : Mono <Void >
2023}
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import org.springframework.web.bind.annotation.ResponseBody
88import org.springframework.web.bind.annotation.RestControllerAdvice
99import org.springframework.web.bind.support.WebExchangeBindException
1010import org.springframework.web.server.ServerWebExchange
11- import reactor.core.publisher.Flux
1211import reactor.core.publisher.Mono
1312import reactor.kotlin.core.publisher.toMono
1413import java.util.stream.Collectors
@@ -32,4 +31,7 @@ class GlobalExceptionHandler {
3231 ).toMono()
3332 }
3433 // need to implement error logging publish to kafka
34+ // detail message = WebExchangeBindException.message
35+
36+
3537}
Original file line number Diff line number Diff line change @@ -26,4 +26,8 @@ class FilmControllerImpl(
2626 .flatMap { toBeSavedFilm.toMono() }
2727 }
2828
29+ override fun deleteFilm (filmId : Int ) : Mono <Void > {
30+ return filmService.deleteFilm(filmId)
31+ }
32+
2933}
Original file line number Diff line number Diff line change @@ -22,4 +22,12 @@ class FilmService(
2222 fun saveFilm (toBeSavedFilm : FilmEntity ) : Mono <FilmEntity > {
2323 return filmRepository.save(toBeSavedFilm);
2424 }
25+
26+ fun deleteFilm (filmId : Int ) : Mono <Void > {
27+ // need to implement cascade delete for table data that set foreign key
28+ return filmRepository.findById(filmId)
29+ .switchIfEmpty(Mono .error(RuntimeException (" Not registered film" )))
30+ .flatMap { filmRepository.deleteById(filmId) }
31+ .then()
32+ }
2533}
You can’t perform that action at this time.
0 commit comments