forked from Cookies_Github_mirror/AquaDX
[+] Keychip session
This commit is contained in:
@@ -3,7 +3,7 @@ package icu.samnyan.aqua.net
|
||||
import ext.*
|
||||
import icu.samnyan.aqua.net.components.*
|
||||
import icu.samnyan.aqua.net.db.*
|
||||
import icu.samnyan.aqua.net.db.AquaUserValidator.Companion.SETTING_FIELDS
|
||||
import icu.samnyan.aqua.net.db.AquaUserServices.Companion.SETTING_FIELDS
|
||||
import icu.samnyan.aqua.net.utils.SUCCESS
|
||||
import icu.samnyan.aqua.sega.general.dao.CardRepository
|
||||
import icu.samnyan.aqua.sega.general.model.Card
|
||||
@@ -26,7 +26,7 @@ class UserRegistrar(
|
||||
val confirmationRepo: EmailConfirmationRepo,
|
||||
val cardRepo: CardRepository,
|
||||
val cardService: CardService,
|
||||
val validator: AquaUserValidator,
|
||||
val validator: AquaUserServices,
|
||||
val emailProps: EmailProperties
|
||||
) {
|
||||
companion object {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import ext.Str
|
||||
import ext.isValidEmail
|
||||
import ext.minus
|
||||
import icu.samnyan.aqua.sega.allnet.KeychipSession
|
||||
import icu.samnyan.aqua.sega.general.model.Card
|
||||
import jakarta.persistence.*
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
@@ -59,7 +60,17 @@ class AquaNetUser(
|
||||
|
||||
// One user can have multiple cards
|
||||
@OneToMany(mappedBy = "aquaUser", cascade = [CascadeType.ALL])
|
||||
var cards: MutableList<Card> = mutableListOf()
|
||||
var cards: MutableList<Card> = mutableListOf(),
|
||||
|
||||
// Each user can have one keychip (if the user owns a cabinet)
|
||||
@JsonIgnore
|
||||
@Column(nullable = true, length = 32, unique = true)
|
||||
var keychip: Str? = null,
|
||||
|
||||
// Each user's keychip can have multiple sessions
|
||||
@JsonIgnore
|
||||
@OneToMany(mappedBy = "user", cascade = [CascadeType.ALL])
|
||||
var keychipSessions: MutableList<KeychipSession> = mutableListOf(),
|
||||
) : Serializable {
|
||||
val computedName get() = displayName.ifEmpty { username }
|
||||
}
|
||||
@@ -69,9 +80,7 @@ interface AquaNetUserRepo : JpaRepository<AquaNetUser, Long> {
|
||||
fun findByAuId(auId: Long): AquaNetUser?
|
||||
fun findByEmailIgnoreCase(email: String): AquaNetUser?
|
||||
fun findByUsernameIgnoreCase(username: String): AquaNetUser?
|
||||
|
||||
fun <T> byName(username: Str, callback: (AquaNetUser) -> T) =
|
||||
findByUsernameIgnoreCase(username)?.let(callback) ?: (404 - "User not found")
|
||||
fun findByKeychip(keychip: String): AquaNetUser?
|
||||
}
|
||||
|
||||
data class SettingField(
|
||||
@@ -85,12 +94,12 @@ data class SettingField(
|
||||
* throw an ApiException if the field is invalid.
|
||||
*/
|
||||
@Service
|
||||
class AquaUserValidator(
|
||||
class AquaUserServices(
|
||||
val userRepo: AquaNetUserRepo,
|
||||
val hasher: PasswordEncoder,
|
||||
) {
|
||||
companion object {
|
||||
val SETTING_FIELDS = AquaUserValidator::class.functions
|
||||
val SETTING_FIELDS = AquaUserServices::class.functions
|
||||
.filter { it.name.startsWith("check") }
|
||||
.map {
|
||||
val name = it.name.removePrefix("check").replaceFirstChar { c -> c.lowercase() }
|
||||
@@ -99,6 +108,9 @@ class AquaUserValidator(
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> byName(username: Str, callback: (AquaNetUser) -> T) =
|
||||
userRepo.findByUsernameIgnoreCase(username)?.let(callback) ?: (404 - "User not found")
|
||||
|
||||
fun checkUsername(username: Str) = username.apply {
|
||||
// Check if username is valid
|
||||
if (length < 2) 400 - "Username must be at least 2 letters"
|
||||
|
||||
@@ -4,7 +4,7 @@ import ext.API
|
||||
import ext.RP
|
||||
import ext.Str
|
||||
import ext.minus
|
||||
import icu.samnyan.aqua.net.db.AquaNetUserRepo
|
||||
import icu.samnyan.aqua.net.db.AquaUserServices
|
||||
import icu.samnyan.aqua.sega.maimai2.dao.userdata.UserDataRepository
|
||||
import icu.samnyan.aqua.sega.maimai2.dao.userdata.UserGeneralDataRepository
|
||||
import icu.samnyan.aqua.sega.maimai2.dao.userdata.UserPlaylogRepository
|
||||
@@ -13,14 +13,13 @@ import org.springframework.web.bind.annotation.RestController
|
||||
@RestController
|
||||
@API("api/v2/game/maimai2")
|
||||
class Maimai2(
|
||||
val user: AquaNetUserRepo,
|
||||
val us: AquaUserServices,
|
||||
val userPlaylogRepository: UserPlaylogRepository,
|
||||
val userDataRepository: UserDataRepository,
|
||||
val userGeneralDataRepository: UserGeneralDataRepository
|
||||
)
|
||||
): GameApiController
|
||||
{
|
||||
@API("trend")
|
||||
fun trend(@RP username: Str): List<TrendOut> = user.byName(username) { u ->
|
||||
override fun trend(@RP username: Str): List<TrendOut> = us.byName(username) { u ->
|
||||
// O(n log n) sort
|
||||
val d = userPlaylogRepository.findByUser_Card_ExtId(u.ghostCard.extId).sortedBy { it.playDate }.toList()
|
||||
|
||||
@@ -45,8 +44,7 @@ class Maimai2(
|
||||
98.0 to "S+",
|
||||
97.0 to "S").map { (k, v) -> (k * 10000).toInt() to v }
|
||||
|
||||
@API("user-summary")
|
||||
fun userSummary(@RP username: Str) = user.byName(username) { u ->
|
||||
override fun userSummary(@RP username: Str) = us.byName(username) { u ->
|
||||
// Summary values: total plays, player rating, server-wide ranking
|
||||
// number of each rank, max combo, number of full combo, number of all perfect
|
||||
val user = userDataRepository.findByCard(u.ghostCard) ?: (404 - "User not found")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package icu.samnyan.aqua.net.games
|
||||
|
||||
import ext.API
|
||||
|
||||
data class TrendOut(val date: String, val rating: Int, val plays: Int)
|
||||
|
||||
data class GenericGamePlaylog(
|
||||
@@ -34,4 +36,11 @@ data class GenericGameSummary(
|
||||
val ratingComposition: Map<String, Any>,
|
||||
|
||||
val recent: List<GenericGamePlaylog>
|
||||
)
|
||||
)
|
||||
|
||||
interface GameApiController {
|
||||
@API("trend")
|
||||
fun trend(username: String): List<TrendOut>
|
||||
@API("user-summary")
|
||||
fun userSummary(username: String): GenericGameSummary
|
||||
}
|
||||
Reference in New Issue
Block a user