mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-13 09:37:27 +08:00
[+] Recent endpoint
This commit is contained in:
@@ -2,6 +2,7 @@ package icu.samnyan.aqua.net.db
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import ext.Str
|
import ext.Str
|
||||||
|
import ext.async
|
||||||
import ext.isValidEmail
|
import ext.isValidEmail
|
||||||
import ext.minus
|
import ext.minus
|
||||||
import icu.samnyan.aqua.sega.allnet.KeychipSession
|
import icu.samnyan.aqua.sega.allnet.KeychipSession
|
||||||
@@ -111,13 +112,13 @@ class AquaUserServices(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> byName(username: Str, callback: (AquaNetUser) -> T) =
|
suspend fun <T> byName(username: Str, callback: suspend (AquaNetUser) -> T) =
|
||||||
userRepo.findByUsernameIgnoreCase(username)?.let(callback) ?: (404 - "User not found")
|
async { userRepo.findByUsernameIgnoreCase(username) }?.let { callback(it) } ?: (404 - "User not found")
|
||||||
|
|
||||||
fun <T> cardByName(username: Str, callback: (Card) -> T) =
|
suspend fun <T> cardByName(username: Str, callback: suspend (Card) -> T) =
|
||||||
if (username.startsWith("user")) username.substring(4).toLongOrNull()
|
if (username.startsWith("user")) username.substring(4).toLongOrNull()
|
||||||
?.let { cardRepo.findById(it).getOrNull() }
|
?.let { cardRepo.findById(it).getOrNull() }
|
||||||
?.let(callback) ?: (404 - "Card not found")
|
?.let { callback(it) } ?: (404 - "Card not found")
|
||||||
else byName(username) { callback(it.ghostCard) }
|
else byName(username) { callback(it.ghostCard) }
|
||||||
|
|
||||||
fun checkUsername(username: Str) = username.apply {
|
fun checkUsername(username: Str) = username.apply {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Chusan(
|
|||||||
val userGeneralDataRepository: UserGeneralDataRepository
|
val userGeneralDataRepository: UserGeneralDataRepository
|
||||||
): GameApiController
|
): GameApiController
|
||||||
{
|
{
|
||||||
override fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
override suspend fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
||||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||||
.map { TrendLog(it.playDate.toString(), it.playerRating) })
|
.map { TrendLog(it.playDate.toString(), it.playerRating) })
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ class Chusan(
|
|||||||
// Only show > AAA rank
|
// Only show > AAA rank
|
||||||
private val shownRanks = chu3Scores.filter { it.first >= 95 * 10000 }
|
private val shownRanks = chu3Scores.filter { it.first >= 95 * 10000 }
|
||||||
|
|
||||||
override fun userSummary(@RP username: Str) = us.cardByName(username) { card ->
|
override suspend fun userSummary(@RP username: Str) = us.cardByName(username) { card ->
|
||||||
// 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 extra = userGeneralDataRepository.findByUser_Card_ExtId(card.extId)
|
val extra = userGeneralDataRepository.findByUser_Card_ExtId(card.extId)
|
||||||
@@ -42,7 +42,11 @@ class Chusan(
|
|||||||
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, ratingComposition)
|
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, ratingComposition)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
override suspend fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
||||||
|
|
||||||
override fun playlog(@RP id: Long) = userPlaylogRepository.findById(id).getOrNull() ?: (404 - "Playlog not found")
|
override suspend fun playlog(@RP id: Long) = userPlaylogRepository.findById(id).getOrNull() ?: (404 - "Playlog not found")
|
||||||
|
|
||||||
|
override suspend fun recent(@RP username: Str) = us.cardByName(username) { card ->
|
||||||
|
userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@ class Maimai2(
|
|||||||
val userGeneralDataRepository: UserGeneralDataRepository
|
val userGeneralDataRepository: UserGeneralDataRepository
|
||||||
): GameApiController
|
): GameApiController
|
||||||
{
|
{
|
||||||
override fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
override suspend fun trend(@RP username: Str): List<TrendOut> = us.cardByName(username) { card ->
|
||||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||||
.map { TrendLog(it.playDate, it.afterRating) })
|
.map { TrendLog(it.playDate, it.afterRating) })
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ class Maimai2(
|
|||||||
// Only show > S rank
|
// Only show > S rank
|
||||||
private val shownRanks = mai2Scores.filter { it.first >= 97 * 10000 }
|
private val shownRanks = mai2Scores.filter { it.first >= 97 * 10000 }
|
||||||
|
|
||||||
override fun userSummary(@RP username: Str) = us.cardByName(username) { card ->
|
override suspend fun userSummary(@RP username: Str) = us.cardByName(username) { card ->
|
||||||
val extra = userGeneralDataRepository.findByUser_Card_ExtId(card.extId)
|
val extra = userGeneralDataRepository.findByUser_Card_ExtId(card.extId)
|
||||||
.associate { it.propertyKey to it.propertyValue }
|
.associate { it.propertyKey to it.propertyValue }
|
||||||
|
|
||||||
@@ -41,7 +41,11 @@ class Maimai2(
|
|||||||
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, ratingComposition)
|
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, ratingComposition)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
override suspend fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
||||||
|
|
||||||
override fun playlog(@RP id: Long) = userPlaylogRepository.findById(id).getOrNull() ?: (404 - "Playlog not found")
|
override suspend fun playlog(@RP id: Long) = userPlaylogRepository.findById(id).getOrNull() ?: (404 - "Playlog not found")
|
||||||
|
|
||||||
|
override suspend fun recent(@RP username: Str) = us.cardByName(username) { card ->
|
||||||
|
userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -46,11 +46,13 @@ data class GenericRankingPlayer(
|
|||||||
|
|
||||||
interface GameApiController {
|
interface GameApiController {
|
||||||
@API("trend")
|
@API("trend")
|
||||||
fun trend(@RP username: String): List<TrendOut>
|
suspend fun trend(@RP username: String): List<TrendOut>
|
||||||
@API("user-summary")
|
@API("user-summary")
|
||||||
fun userSummary(@RP username: String): GenericGameSummary
|
suspend fun userSummary(@RP username: String): GenericGameSummary
|
||||||
@API("ranking")
|
@API("ranking")
|
||||||
fun ranking(): List<GenericRankingPlayer>
|
suspend fun ranking(): List<GenericRankingPlayer>
|
||||||
@API("playlog")
|
@API("playlog")
|
||||||
fun playlog(@RP id: Long): IGenericGamePlaylog
|
suspend fun playlog(@RP id: Long): IGenericGamePlaylog
|
||||||
|
@API("recent")
|
||||||
|
suspend fun recent(@RP username: String): List<IGenericGamePlaylog>
|
||||||
}
|
}
|
||||||
@@ -18,14 +18,14 @@ class Ongeki(
|
|||||||
val userDataRepository: UserDataRepository,
|
val userDataRepository: UserDataRepository,
|
||||||
val userGeneralDataRepository: UserGeneralDataRepository
|
val userGeneralDataRepository: UserGeneralDataRepository
|
||||||
): GameApiController {
|
): GameApiController {
|
||||||
override fun trend(username: String) = us.cardByName(username) { card ->
|
override suspend fun trend(username: String) = us.cardByName(username) { card ->
|
||||||
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
findTrend(userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||||
.map { TrendLog(it.playDate, it.playerRating) })
|
.map { TrendLog(it.playDate, it.playerRating) })
|
||||||
}
|
}
|
||||||
|
|
||||||
private val shownRanks = ongekiScores.filter { it.first >= 950000 }
|
private val shownRanks = ongekiScores.filter { it.first >= 950000 }
|
||||||
|
|
||||||
override fun userSummary(username: String) = us.cardByName(username) { card ->
|
override suspend fun userSummary(username: String) = us.cardByName(username) { card ->
|
||||||
// val extra = userGeneralDataRepository.findByUser_Card_ExtId(u.ghostCard.extId)
|
// val extra = userGeneralDataRepository.findByUser_Card_ExtId(u.ghostCard.extId)
|
||||||
// .associate { it.propertyKey to it.propertyValue }
|
// .associate { it.propertyKey to it.propertyValue }
|
||||||
|
|
||||||
@@ -34,7 +34,11 @@ class Ongeki(
|
|||||||
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, mapOf())
|
genericUserSummary(card, userDataRepository, userPlaylogRepository, shownRanks, mapOf())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
override suspend fun ranking() = genericRanking(userDataRepository, userPlaylogRepository)
|
||||||
|
|
||||||
override fun playlog(id: Long) = userPlaylogRepository.findById(id).getOrNull() ?: (404 - "Playlog not found")
|
override suspend fun playlog(id: Long) = userPlaylogRepository.findById(id).getOrNull() ?: (404 - "Playlog not found")
|
||||||
|
|
||||||
|
override suspend fun recent(username: String) = us.cardByName(username) { card ->
|
||||||
|
userPlaylogRepository.findByUser_Card_ExtId(card.extId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user