mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-10 17:37:27 +08:00
[+] Default game endpoint
This commit is contained in:
@@ -2,6 +2,7 @@ package icu.samnyan.aqua.net
|
|||||||
|
|
||||||
import ext.*
|
import ext.*
|
||||||
import icu.samnyan.aqua.net.components.JWT
|
import icu.samnyan.aqua.net.components.JWT
|
||||||
|
import icu.samnyan.aqua.net.db.AquaUserServices
|
||||||
import icu.samnyan.aqua.net.utils.AquaNetProps
|
import icu.samnyan.aqua.net.utils.AquaNetProps
|
||||||
import icu.samnyan.aqua.net.utils.GenericUserDataRepo
|
import icu.samnyan.aqua.net.utils.GenericUserDataRepo
|
||||||
import icu.samnyan.aqua.net.utils.IGenericUserData
|
import icu.samnyan.aqua.net.utils.IGenericUserData
|
||||||
@@ -17,6 +18,7 @@ import kotlin.jvm.optionals.getOrNull
|
|||||||
@API("/api/v2/card")
|
@API("/api/v2/card")
|
||||||
class CardController(
|
class CardController(
|
||||||
val jwt: JWT,
|
val jwt: JWT,
|
||||||
|
val us: AquaUserServices,
|
||||||
val cardService: CardService,
|
val cardService: CardService,
|
||||||
val cardGameService: CardGameService,
|
val cardGameService: CardGameService,
|
||||||
val cardRepository: CardRepository,
|
val cardRepository: CardRepository,
|
||||||
@@ -94,6 +96,12 @@ class CardController(
|
|||||||
|
|
||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@API("/default-game")
|
||||||
|
@Doc("Get the default game for the card.", "Game ID")
|
||||||
|
suspend fun defaultGame(@RP username: Str) = us.cardByName(username) { card ->
|
||||||
|
cardGameService.getSummary(card).filterValues { it != null }.keys.firstOrNull()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,8 +148,8 @@ class CardGameService(
|
|||||||
// An easy migration is to change the UserData card field to the user's ghost card
|
// An easy migration is to change the UserData card field to the user's ghost card
|
||||||
games.forEach { game ->
|
games.forEach { game ->
|
||||||
when (game) {
|
when (game) {
|
||||||
"maimai2" -> migrateCard(maimai2, crd)
|
"mai2" -> migrateCard(maimai2, crd)
|
||||||
"chusan" -> migrateCard(chusan, crd)
|
"chu3" -> migrateCard(chusan, crd)
|
||||||
"ongeki" -> migrateCard(ongeki, crd)
|
"ongeki" -> migrateCard(ongeki, crd)
|
||||||
// TODO: diva
|
// TODO: diva
|
||||||
// "diva" -> diva.findByPdId(card.extId.toInt()).getOrNull()?.let {
|
// "diva" -> diva.findByPdId(card.extId.toInt()).getOrNull()?.let {
|
||||||
@@ -152,8 +160,8 @@ class CardGameService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getSummary(card: Card) = async { mapOf(
|
suspend fun getSummary(card: Card) = async { mapOf(
|
||||||
"maimai2" to getSummaryFor(maimai2, card),
|
"mai2" to getSummaryFor(maimai2, card),
|
||||||
"chusan" to getSummaryFor(chusan, card),
|
"chu3" to getSummaryFor(chusan, card),
|
||||||
"ongeki" to getSummaryFor(ongeki, card),
|
"ongeki" to getSummaryFor(ongeki, card),
|
||||||
"diva" to diva.findByPdId(card.extId.toInt()).getOrNull()?.let {
|
"diva" to diva.findByPdId(card.extId.toInt()).getOrNull()?.let {
|
||||||
mapOf(
|
mapOf(
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ fun genericUserSummary(
|
|||||||
): GenericGameSummary {
|
): GenericGameSummary {
|
||||||
// Summary values: total plays, player rating, server-wide ranking
|
// Summary values: total plays, player rating, server-wide ranking
|
||||||
// number of each rank, max combo, number of full combo, number of all perfect
|
// number of each rank, max combo, number of full combo, number of all perfect
|
||||||
val user = userDataRepo.findByCard(card) ?: (404 - "User not found")
|
val user = userDataRepo.findByCard(card) ?: (404 - "Game data not found")
|
||||||
val plays = userPlaylogRepo.findByUserCardExtId(card.extId)
|
val plays = userPlaylogRepo.findByUserCardExtId(card.extId)
|
||||||
|
|
||||||
// O(6n) ranks algorithm: Loop through the entire list of plays,
|
// O(6n) ranks algorithm: Loop through the entire list of plays,
|
||||||
|
|||||||
Reference in New Issue
Block a user