Skip to content

Commit

Permalink
Demo search on frontend
Browse files Browse the repository at this point in the history
### What's done:
* Replaced stub demoList with functional one
* Added demo filtering
* Implemented useDebouncedDeferredRequest

(#2057)
  • Loading branch information
sanyavertolet committed Mar 31, 2023
1 parent 660f7be commit 85766d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.kotlin.core.publisher.toMono

import reactor.kotlin.core.util.function.component1
import reactor.kotlin.core.util.function.component2
Expand All @@ -43,14 +44,15 @@ class DemoController(
*/
@PostMapping("/demo-list")
fun getFilteredDemoList(
@RequestBody(required = false) filter: DemoFilter = DemoFilter.any,
@RequestBody(required = false) filter: DemoFilter?,
@RequestParam(required = false, defaultValue = DemoDto.DEFAULT_FETCH_NUMBER.toString())
demoAmount: Int = DemoDto.DEFAULT_FETCH_NUMBER,
): Flux<DemoDto> = blockingToFlux {
demoService.getFiltered(filter, demoAmount).toList().map { it to demoService.getStatus(it).block() }
}
.filter { (_, status) -> status in filter.statuses }
.map { it.first.toDto() }
): Flux<DemoDto> = filter.toMono()
.switchIfEmpty(DemoFilter.any.toMono())
.flatMapMany { demoFilter ->
blockingToFlux { demoService.getFiltered(demoFilter, demoAmount) }
}
.map { it.toDto() }

/**
* @param organizationName saveourtool organization name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.saveourtool.save.utils.StringResponse
import com.saveourtool.save.utils.blockingToMono
import com.saveourtool.save.utils.switchIfEmptyToNotFound

import org.springframework.data.domain.Page
import org.springframework.data.domain.PageRequest
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
Expand Down Expand Up @@ -95,7 +94,7 @@ class DemoService(
* @param pageSize amount of [Demo]s that should be fetched
* @return list of [Demo]s that match [DemoFilter]
*/
fun getFiltered(demoFilter: DemoFilter, pageSize: Int): Page<Demo> = demoRepository.findAll({ root, _, cb ->
fun getFiltered(demoFilter: DemoFilter, pageSize: Int): List<Demo> = demoRepository.findAll({ root, _, cb ->
with(demoFilter) {
val organizationNamePredicate = if (organizationName.isBlank()) {
cb.and()
Expand All @@ -114,6 +113,8 @@ class DemoService(
)
}
}, PageRequest.ofSize(pageSize))
.filter { demoFilter.statuses.isEmpty() || getStatus(it).block() in demoFilter.statuses }
.toList()

/**
* @param demo [Demo] entity
Expand Down Expand Up @@ -154,6 +155,7 @@ class DemoService(
* @param projectName saveourtool project name
* @return [Demo] connected with project [organizationName]/[projectName] or null if not present
*/
@Transactional(readOnly = true)
fun findBySaveourtoolProject(
organizationName: String,
projectName: String,
Expand Down

0 comments on commit 85766d7

Please sign in to comment.