Skip to content

Commit

Permalink
FEATURE: Film delete API added #4
Browse files Browse the repository at this point in the history
  • Loading branch information
stephano-tri committed Jan 30, 2024
1 parent b6a81c9 commit 428706f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ interface FilmController {

@PostMapping("/save")
fun saveFilm(@Valid @RequestBody toBeSavedFilm : Film) : Mono<Film>

@DeleteMapping("/delete/{filmId}")
fun deleteFilm(@PathVariable filmId : Int) : Mono<Void>
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.bind.support.WebExchangeBindException
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.kotlin.core.publisher.toMono
import java.util.stream.Collectors
Expand All @@ -32,4 +31,7 @@ class GlobalExceptionHandler {
).toMono()
}
// need to implement error logging publish to kafka
// detail message = WebExchangeBindException.message


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ class FilmControllerImpl(
.flatMap { toBeSavedFilm.toMono() }
}

override fun deleteFilm(filmId : Int) : Mono<Void> {
return filmService.deleteFilm(filmId)
}

}
8 changes: 8 additions & 0 deletions src/main/kotlin/eom/improve/kafkaboot/service/FilmService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ class FilmService(
fun saveFilm(toBeSavedFilm : FilmEntity) : Mono<FilmEntity> {
return filmRepository.save(toBeSavedFilm);
}

fun deleteFilm(filmId : Int) : Mono<Void> {
// need to implement cascade delete for table data that set foreign key
return filmRepository.findById(filmId)
.switchIfEmpty(Mono.error(RuntimeException("Not registered film")))
.flatMap { filmRepository.deleteById(filmId) }
.then()
}
}

1 comment on commit 428706f

@stephano-tri
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to implementation cascade delete for foreign key table

Please sign in to comment.