From 83aac1de030db4a6b740e9f89403edfb4e4adf5c Mon Sep 17 00:00:00 2001 From: stephano-tri Date: Thu, 22 Aug 2024 23:46:20 +0900 Subject: [PATCH] FEATURE : add search criteria in controller #4 --- .../kotlin/eom/improve/kafkaboot/common/SearchCriteria.kt | 8 ++++++++ .../eom/improve/kafkaboot/controller/FilmController.kt | 4 +++- .../eom/improve/kafkaboot/service/FilmControllerImpl.kt | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/eom/improve/kafkaboot/common/SearchCriteria.kt diff --git a/src/main/kotlin/eom/improve/kafkaboot/common/SearchCriteria.kt b/src/main/kotlin/eom/improve/kafkaboot/common/SearchCriteria.kt new file mode 100644 index 0000000..343b64c --- /dev/null +++ b/src/main/kotlin/eom/improve/kafkaboot/common/SearchCriteria.kt @@ -0,0 +1,8 @@ +package eom.improve.kafkaboot.common + +// change SearchCriteria to data class +data class SearchCriteria( + var name: String? = null, + var from: Int? = null, + var to: Int? = null +) diff --git a/src/main/kotlin/eom/improve/kafkaboot/controller/FilmController.kt b/src/main/kotlin/eom/improve/kafkaboot/controller/FilmController.kt index 1838de6..614310d 100644 --- a/src/main/kotlin/eom/improve/kafkaboot/controller/FilmController.kt +++ b/src/main/kotlin/eom/improve/kafkaboot/controller/FilmController.kt @@ -11,7 +11,9 @@ import reactor.core.publisher.Mono interface FilmController { @GetMapping("/list/all") - fun getAllFilms() : Mono> + fun getAllFilms(@RequestParam name : String?, + @RequestParam from : Int?, + @RequestParam to : Int?) : Mono> @GetMapping("/list/{page}/{limit}") fun getFilms(@PathVariable page: Long, @PathVariable limit: Long) : Mono> diff --git a/src/main/kotlin/eom/improve/kafkaboot/service/FilmControllerImpl.kt b/src/main/kotlin/eom/improve/kafkaboot/service/FilmControllerImpl.kt index f37efe5..4b4908a 100644 --- a/src/main/kotlin/eom/improve/kafkaboot/service/FilmControllerImpl.kt +++ b/src/main/kotlin/eom/improve/kafkaboot/service/FilmControllerImpl.kt @@ -1,6 +1,7 @@ package eom.improve.kafkaboot.service import eom.improve.kafkaboot.common.PaginatedResponse +import eom.improve.kafkaboot.common.SearchCriteria import eom.improve.kafkaboot.controller.FilmController import eom.improve.kafkaboot.dto.Film import org.springframework.data.domain.PageRequest @@ -13,7 +14,7 @@ class FilmControllerImpl( private val filmService: FilmService ) : FilmController{ - override fun getAllFilms(): Mono> { + override fun getAllFilms(searchCriteria : SearchCriteria): Mono> { return filmService.findAll().map { it.convert2Pojo() } .collectSortedList((Comparator { o1, o2 -> o1.filmId.compareTo(o2.filmId) })) }