companion object Table : DocumentTable<User> by DocumentTable.create({
unique(User::discordId)
+ index(User::registeredAt)
})
}
suspend fun del(id: Id<T>)
suspend fun all(): Flow<T>
- suspend fun select(bson: Bson): Flow<T>
- suspend fun locate(bson: Bson): T?
+ suspend fun select(where: Bson): Flow<T>
+ suspend fun sorted(order: Bson): Flow<T>
+ suspend fun locate(where: Bson): T?
suspend fun update(where: Bson, set: Bson)
suspend fun remove(where: Bson)
return collection().find().toFlow()
}
- override suspend fun select(bson: Bson): Flow<T> {
- return collection().find(bson).toFlow()
+ override suspend fun select(where: Bson): Flow<T> {
+ return collection().find(where).toFlow()
}
- override suspend fun locate(bson: Bson): T? {
- return collection().findOne(bson)
+ override suspend fun sorted(order: Bson): Flow<T> {
+ return collection().find().sort(order).toFlow()
+ }
+
+ override suspend fun locate(where: Bson): T? {
+ return collection().findOne(where)
}
override suspend fun update(where: Bson, set: Bson) {
call.respondHtml(HttpStatusCode.OK, call.aboutPage())
}
+ get("/users") {
+ call.respondHtml(HttpStatusCode.OK, call.newUsersPage())
+ }
+
// Random name generation
get("/generate-name/{flavor}/{gender}") {
val flavor = call.parameters["flavor"]?.let { flavor -> AdmiralNameFlavor.values().singleOrNull { it.toUrlSlug() == flavor.lowercase() } }!!
NavLink("/", "Main Page"),
NavLink("/info", "Read Manual"),
NavLink("/about", "About Starship Fights"),
+ NavLink("/users", "New Users"),
NavHead("Your Account"),
) + when (val user = getUser()) {
null -> listOf(
package starshipfights.info
import io.ktor.application.*
+import kotlinx.coroutines.flow.take
+import kotlinx.coroutines.flow.toList
import kotlinx.html.*
+import org.litote.kmongo.descending
+import starshipfights.data.auth.User
suspend fun ApplicationCall.mainPage(): HTML.() -> Unit {
return page(null, standardNavBar(), IndexSidebar) {
}
}
}
+
+suspend fun ApplicationCall.newUsersPage(): HTML.() -> Unit {
+ val newUsers = User.sorted(descending(User::registeredAt)).take(20).toList()
+
+ return page("New Users", standardNavBar(), IndexSidebar) {
+ section {
+ h1 { +"New Users" }
+ }
+ div {
+ style = "text-align:center"
+ newUsers.forEach { newUser ->
+ div {
+ style = "display:inline-block;width:24%"
+ img(src = newUser.discordAvatarUrl) { style = "width:100%" }
+ p {
+ style = "text-align:center"
+ a(href = "/user/${newUser.id}") {
+ +newUser.profileName
+ }
+ }
+ }
+ }
+ }
+ }
+}