forked from SteamWar/SteamWar
Format code
This commit is contained in:
@@ -56,9 +56,12 @@ fun Route.configureAuditLog() {
|
||||
val serverOwner = call.request.queryParameters.getAll("serverOwner")?.map { it.toInt() }?.toSet()
|
||||
val velocity = call.request.queryParameters["velocity"]?.toBoolean()
|
||||
|
||||
val page = call.request.queryParameters["page"]?.toIntOrNull() ?: 0
|
||||
val limit = call.request.queryParameters["limit"]?.toIntOrNull() ?: 100
|
||||
val sorting = call.request.queryParameters["sorting"] ?: "DESC"
|
||||
val page = call.request.queryParameters["page"]?.toIntOrNull()
|
||||
?: 0
|
||||
val limit = call.request.queryParameters["limit"]?.toIntOrNull()
|
||||
?: 100
|
||||
val sorting = call.request.queryParameters["sorting"]
|
||||
?: "DESC"
|
||||
|
||||
call.respond(
|
||||
PagedAuditLog.filter(
|
||||
@@ -97,41 +100,30 @@ data class PagedAuditLog(val rows: Long, val entries: List<AuditLogEntry>) {
|
||||
page: Int = 0,
|
||||
limit: Int = 100,
|
||||
sorting: String = "DESC"
|
||||
) = useDb {
|
||||
val actorTable = SteamwarUserTable.alias("actor")
|
||||
val serverOwnerTable = SteamwarUserTable.alias("serverOwner")
|
||||
) =
|
||||
useDb {
|
||||
val actorTable = SteamwarUserTable.alias("actor")
|
||||
val serverOwnerTable = SteamwarUserTable.alias("serverOwner")
|
||||
|
||||
val query = AuditLogTable.join(
|
||||
actorTable,
|
||||
JoinType.INNER,
|
||||
onColumn = actorTable[SteamwarUserTable.id],
|
||||
otherColumn = AuditLogTable.actor
|
||||
)
|
||||
.join(
|
||||
serverOwnerTable,
|
||||
JoinType.LEFT,
|
||||
onColumn = serverOwnerTable[SteamwarUserTable.id],
|
||||
otherColumn = AuditLogTable.serverOwner
|
||||
)
|
||||
.select(
|
||||
actorTable[SteamwarUserTable.username], serverOwnerTable[SteamwarUserTable.username],
|
||||
*AuditLogTable.columns.toTypedArray()
|
||||
val query = AuditLogTable.join(
|
||||
actorTable,
|
||||
JoinType.INNER,
|
||||
onColumn = actorTable[SteamwarUserTable.id],
|
||||
otherColumn = AuditLogTable.actor
|
||||
)
|
||||
.join(
|
||||
serverOwnerTable,
|
||||
JoinType.LEFT,
|
||||
onColumn = serverOwnerTable[SteamwarUserTable.id],
|
||||
otherColumn = AuditLogTable.serverOwner
|
||||
)
|
||||
.select(
|
||||
actorTable[SteamwarUserTable.username], serverOwnerTable[SteamwarUserTable.username],
|
||||
*AuditLogTable.columns.toTypedArray()
|
||||
)
|
||||
|
||||
PagedAuditLog(
|
||||
AuditLogTable.selectAll().addAuditLogFilters(
|
||||
actionText,
|
||||
serverText,
|
||||
fullText,
|
||||
actor,
|
||||
actionType,
|
||||
timeGreater,
|
||||
timeLess,
|
||||
serverOwner,
|
||||
velocity
|
||||
).count(),
|
||||
query
|
||||
.addAuditLogFilters(
|
||||
PagedAuditLog(
|
||||
AuditLogTable.selectAll().addAuditLogFilters(
|
||||
actionText,
|
||||
serverText,
|
||||
fullText,
|
||||
@@ -141,23 +133,35 @@ data class PagedAuditLog(val rows: Long, val entries: List<AuditLogEntry>) {
|
||||
timeLess,
|
||||
serverOwner,
|
||||
velocity
|
||||
)
|
||||
.limit(limit)
|
||||
.offset((page * limit).toLong())
|
||||
.orderBy(AuditLogTable.time, SortOrder.valueOf(sorting.uppercase()))
|
||||
.map {
|
||||
AuditLogEntry(
|
||||
it[AuditLogTable.id].value,
|
||||
it[AuditLogTable.time].toEpochMilli(),
|
||||
it[AuditLogTable.server],
|
||||
it[serverOwnerTable[SteamwarUserTable.username]],
|
||||
it[actorTable[SteamwarUserTable.username]],
|
||||
it[AuditLogTable.action],
|
||||
it[AuditLogTable.actionText]
|
||||
).count(),
|
||||
query
|
||||
.addAuditLogFilters(
|
||||
actionText,
|
||||
serverText,
|
||||
fullText,
|
||||
actor,
|
||||
actionType,
|
||||
timeGreater,
|
||||
timeLess,
|
||||
serverOwner,
|
||||
velocity
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
.limit(limit)
|
||||
.offset((page * limit).toLong())
|
||||
.orderBy(AuditLogTable.time, SortOrder.valueOf(sorting.uppercase()))
|
||||
.map {
|
||||
AuditLogEntry(
|
||||
it[AuditLogTable.id].value,
|
||||
it[AuditLogTable.time].toEpochMilli(),
|
||||
it[AuditLogTable.server],
|
||||
it[serverOwnerTable[SteamwarUserTable.username]],
|
||||
it[actorTable[SteamwarUserTable.username]],
|
||||
it[AuditLogTable.action],
|
||||
it[AuditLogTable.actionText]
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
private fun Query.addAuditLogFilters(
|
||||
actionText: String? = null,
|
||||
|
||||
Reference in New Issue
Block a user