updating users with pagination
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package ltd.hlaeja.controller
|
||||
|
||||
import ltd.hlaeja.dto.Pagination
|
||||
import ltd.hlaeja.service.AccountRegistryService
|
||||
import org.springframework.stereotype.Controller
|
||||
import org.springframework.ui.Model
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestParam
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Controller
|
||||
@@ -13,18 +14,39 @@ import reactor.core.publisher.Mono
|
||||
class AccountController(
|
||||
private val accountRegistryService: AccountRegistryService,
|
||||
) {
|
||||
companion object {
|
||||
const val DEFAULT_PAGE: Int = 1
|
||||
const val DEFAULT_SIZE: Int = 25
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
fun getAccounts(
|
||||
@RequestParam(defaultValue = "1") page: Int,
|
||||
@RequestParam(defaultValue = "2") size: Int,
|
||||
fun getDefaultAccounts(
|
||||
model: Model,
|
||||
): Mono<String> = accountRegistryService.getAccounts(page, size)
|
||||
): Mono<String> = getAccounts(DEFAULT_PAGE, DEFAULT_SIZE, model)
|
||||
|
||||
@GetMapping("/page-{page}")
|
||||
fun getAccountsPage(
|
||||
@PathVariable page: Int,
|
||||
model: Model,
|
||||
): Mono<String> = getAccounts(page, DEFAULT_SIZE, model)
|
||||
|
||||
@GetMapping("/page-{page}/show-{size}")
|
||||
fun getAccountsPageSize(
|
||||
@PathVariable page: Int,
|
||||
@PathVariable size: Int,
|
||||
model: Model,
|
||||
): Mono<String> = getAccounts(page, size, model)
|
||||
|
||||
private fun getAccounts(
|
||||
page: Int,
|
||||
size: Int,
|
||||
model: Model,
|
||||
) = accountRegistryService.getAccounts(page, size)
|
||||
.collectList()
|
||||
.doOnNext { items ->
|
||||
model.addAttribute("items", items)
|
||||
model.addAttribute("page", page)
|
||||
model.addAttribute("size", size)
|
||||
model.addAttribute("pagination", Pagination(page, size, items.size, DEFAULT_SIZE))
|
||||
}
|
||||
.then(Mono.just("account/users"))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user