diff --git a/app/src/routes/RemoteTable.svelte b/app/src/routes/RemoteTable.svelte index cc9621e..fd98fd4 100644 --- a/app/src/routes/RemoteTable.svelte +++ b/app/src/routes/RemoteTable.svelte @@ -8,7 +8,7 @@ let rows = []; let page = 0; //first page let pageIndex = 0; //first row - let pageSize = 10; //optional, 10 by default + let pageSize = 15; //optional, 10 by default let loading = true; let rowsCount = 0; diff --git a/src/main/kotlin/io/github/wulkanowy/schools/dao/LoginEventDao.kt b/src/main/kotlin/io/github/wulkanowy/schools/dao/LoginEventDao.kt index 44f15bd..caa1202 100644 --- a/src/main/kotlin/io/github/wulkanowy/schools/dao/LoginEventDao.kt +++ b/src/main/kotlin/io/github/wulkanowy/schools/dao/LoginEventDao.kt @@ -25,26 +25,33 @@ class LoginEventDao { suspend fun allLoginEvents( page: Long, pageSize: Int, + text: String?, orderBy: Column<*>?, order: SortOrder?, ): List = dbQuery { - LoginEvents - .slice( - customDistinctOn(LoginEvents.schoolId, LoginEvents.symbol, LoginEvents.scraperBaseUrl), - *(LoginEvents.columns).toTypedArray() - ) - .selectAll() - .limit(pageSize, page * pageSize) + getQuery(text) .let { if (orderBy != null && order != null) { it.orderBy(orderBy, order) } else it } + .limit(pageSize, page * pageSize) .map(::resultRowToLoginEvent) } - suspend fun getLoginEventsCount(): Long = dbQuery { - LoginEvents.selectAll().count() + suspend fun getCount(text: String?) = dbQuery { + getQuery(text).count() + } + + private suspend fun getQuery(text: String?) = dbQuery { + LoginEvents + .selectAll() + .let { + if (text.isNullOrBlank()) it else { + it.orWhere { LoginEvents.schoolName like "%${text}%" } + .orWhere { LoginEvents.schoolAddress like "%${text}%" } + } + } } suspend fun addLoginEvent(event: LoginEvent) = withContext(Dispatchers.IO) { diff --git a/src/main/kotlin/io/github/wulkanowy/schools/plugins/Routing.kt b/src/main/kotlin/io/github/wulkanowy/schools/plugins/Routing.kt index eebd102..9a2467c 100644 --- a/src/main/kotlin/io/github/wulkanowy/schools/plugins/Routing.kt +++ b/src/main/kotlin/io/github/wulkanowy/schools/plugins/Routing.kt @@ -47,6 +47,7 @@ fun Application.configureRouting() { rows = loginEventDao.allLoginEvents( page = params["page"]?.toLongOrNull() ?: 0, pageSize = params["pageSize"]?.toIntOrNull() ?: 10, + text = params["text"], orderBy = when (params["sortBy"]) { "id" -> LoginEvents.id "schoolName" -> LoginEvents.schoolName @@ -60,7 +61,7 @@ fun Application.configureRouting() { else -> null }, ), - rowsCount = loginEventDao.getLoginEventsCount(), + rowsCount = loginEventDao.getCount(text = params["text"]), ) ) }