Fix count all when using filtering
This commit is contained in:
parent
df7c57d9d9
commit
386f8cae72
3 changed files with 19 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -25,26 +25,33 @@ class LoginEventDao {
|
|||
suspend fun allLoginEvents(
|
||||
page: Long,
|
||||
pageSize: Int,
|
||||
text: String?,
|
||||
orderBy: Column<*>?,
|
||||
order: SortOrder?,
|
||||
): List<LoginEvent> = 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) {
|
||||
|
|
|
@ -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"]),
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue