Skip to content

Commit 85766d7

Browse files
committed
Demo search on frontend
### What's done: * Replaced stub demoList with functional one * Added demo filtering * Implemented useDebouncedDeferredRequest (#2057)
1 parent 660f7be commit 85766d7

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

save-demo/src/main/kotlin/com/saveourtool/save/demo/controller/DemoController.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam
1919
import org.springframework.web.bind.annotation.RestController
2020
import reactor.core.publisher.Flux
2121
import reactor.core.publisher.Mono
22+
import reactor.kotlin.core.publisher.toMono
2223

2324
import reactor.kotlin.core.util.function.component1
2425
import reactor.kotlin.core.util.function.component2
@@ -43,14 +44,15 @@ class DemoController(
4344
*/
4445
@PostMapping("/demo-list")
4546
fun getFilteredDemoList(
46-
@RequestBody(required = false) filter: DemoFilter = DemoFilter.any,
47+
@RequestBody(required = false) filter: DemoFilter?,
4748
@RequestParam(required = false, defaultValue = DemoDto.DEFAULT_FETCH_NUMBER.toString())
4849
demoAmount: Int = DemoDto.DEFAULT_FETCH_NUMBER,
49-
): Flux<DemoDto> = blockingToFlux {
50-
demoService.getFiltered(filter, demoAmount).toList().map { it to demoService.getStatus(it).block() }
51-
}
52-
.filter { (_, status) -> status in filter.statuses }
53-
.map { it.first.toDto() }
50+
): Flux<DemoDto> = filter.toMono()
51+
.switchIfEmpty(DemoFilter.any.toMono())
52+
.flatMapMany { demoFilter ->
53+
blockingToFlux { demoService.getFiltered(demoFilter, demoAmount) }
54+
}
55+
.map { it.toDto() }
5456

5557
/**
5658
* @param organizationName saveourtool organization name

save-demo/src/main/kotlin/com/saveourtool/save/demo/service/DemoService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.saveourtool.save.utils.StringResponse
1414
import com.saveourtool.save.utils.blockingToMono
1515
import com.saveourtool.save.utils.switchIfEmptyToNotFound
1616

17-
import org.springframework.data.domain.Page
1817
import org.springframework.data.domain.PageRequest
1918
import org.springframework.stereotype.Service
2019
import org.springframework.transaction.annotation.Transactional
@@ -95,7 +94,7 @@ class DemoService(
9594
* @param pageSize amount of [Demo]s that should be fetched
9695
* @return list of [Demo]s that match [DemoFilter]
9796
*/
98-
fun getFiltered(demoFilter: DemoFilter, pageSize: Int): Page<Demo> = demoRepository.findAll({ root, _, cb ->
97+
fun getFiltered(demoFilter: DemoFilter, pageSize: Int): List<Demo> = demoRepository.findAll({ root, _, cb ->
9998
with(demoFilter) {
10099
val organizationNamePredicate = if (organizationName.isBlank()) {
101100
cb.and()
@@ -114,6 +113,8 @@ class DemoService(
114113
)
115114
}
116115
}, PageRequest.ofSize(pageSize))
116+
.filter { demoFilter.statuses.isEmpty() || getStatus(it).block() in demoFilter.statuses }
117+
.toList()
117118

118119
/**
119120
* @param demo [Demo] entity
@@ -154,6 +155,7 @@ class DemoService(
154155
* @param projectName saveourtool project name
155156
* @return [Demo] connected with project [organizationName]/[projectName] or null if not present
156157
*/
158+
@Transactional(readOnly = true)
157159
fun findBySaveourtoolProject(
158160
organizationName: String,
159161
projectName: String,

0 commit comments

Comments
 (0)