mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-04 20:27:27 +08:00
feat: ✨ option APIs for chu3, mai2 & ongeki (#194)
This commit is contained in:
@@ -27,6 +27,7 @@ abstract class GameApiController<T : IUserData>(val name: String, userDataClass:
|
|||||||
abstract val playlogRepo: GenericPlaylogRepo<*>
|
abstract val playlogRepo: GenericPlaylogRepo<*>
|
||||||
abstract val userMusicRepo: GenericUserMusicRepo<*>
|
abstract val userMusicRepo: GenericUserMusicRepo<*>
|
||||||
abstract val shownRanks: List<Pair<Int, String>>
|
abstract val shownRanks: List<Pair<Int, String>>
|
||||||
|
|
||||||
abstract val settableFields: Map<String, (T, String) -> Unit>
|
abstract val settableFields: Map<String, (T, String) -> Unit>
|
||||||
open val gettableFields: Set<String> = setOf()
|
open val gettableFields: Set<String> = setOf()
|
||||||
|
|
||||||
@@ -126,13 +127,11 @@ abstract class GameApiController<T : IUserData>(val name: String, userDataClass:
|
|||||||
(settableFields.keys.toSet() + gettableFields)
|
(settableFields.keys.toSet() + gettableFields)
|
||||||
.associateWith { k -> (vm[k] ?: error("Field $k not found")) }
|
.associateWith { k -> (vm[k] ?: error("Field $k not found")) }
|
||||||
} }
|
} }
|
||||||
|
|
||||||
@API("user-detail")
|
@API("user-detail")
|
||||||
suspend fun userDetail(@RP username: String) = us.cardByName(username) { card ->
|
suspend fun userDetail(@RP username: String) = us.cardByName(username) { card ->
|
||||||
val u = userDataRepo.findByCard(card) ?: (404 - "User not found")
|
val u = userDataRepo.findByCard(card) ?: (404 - "User not found")
|
||||||
userDetailFields.toList().associate { (k, f) -> k to f.invoke(u) }
|
userDetailFields.toList().associate { (k, f) -> k to f.invoke(u) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@API("user-detail-set")
|
@API("user-detail-set")
|
||||||
suspend fun userDetailSet(@RP token: String, @RP field: String, @RP value: String): Any {
|
suspend fun userDetailSet(@RP token: String, @RP field: String, @RP value: String): Any {
|
||||||
val prop = settableFields[field] ?: (400 - "Invalid field $field")
|
val prop = settableFields[field] ?: (400 - "Invalid field $field")
|
||||||
@@ -146,6 +145,11 @@ abstract class GameApiController<T : IUserData>(val name: String, userDataClass:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@API("user-option")
|
||||||
|
open suspend fun userOption(@RP token: String): Any? = 400 - "Unsupported by this game"
|
||||||
|
@API("user-option-set")
|
||||||
|
open suspend fun userOptionSet(@RP token: String, @RP field: String, @RP value: Int): Any = 400 - "Unsupported by this game"
|
||||||
|
|
||||||
@API("user-music-from-list")
|
@API("user-music-from-list")
|
||||||
suspend fun userMusicFromList(@RP username: Str, @RB musicList: List<Int>) = us.cardByName(username) { card ->
|
suspend fun userMusicFromList(@RP username: Str, @RB musicList: List<Int>) = us.cardByName(username) { card ->
|
||||||
userMusicRepo.findByUser_Card_ExtIdAndMusicIdIn(card.extId, musicList)
|
userMusicRepo.findByUser_Card_ExtIdAndMusicIdIn(card.extId, musicList)
|
||||||
|
|||||||
@@ -6,7 +6,12 @@ import icu.samnyan.aqua.net.games.*
|
|||||||
import icu.samnyan.aqua.net.utils.*
|
import icu.samnyan.aqua.net.utils.*
|
||||||
import icu.samnyan.aqua.sega.chusan.model.*
|
import icu.samnyan.aqua.sega.chusan.model.*
|
||||||
import icu.samnyan.aqua.sega.chusan.model.userdata.Chu3UserData
|
import icu.samnyan.aqua.sega.chusan.model.userdata.Chu3UserData
|
||||||
|
import icu.samnyan.aqua.sega.chusan.model.userdata.UserGameOption
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import kotlin.jvm.optionals.getOrNull
|
||||||
|
import kotlin.reflect.KMutableProperty1
|
||||||
|
import kotlin.reflect.full.declaredMemberProperties
|
||||||
|
import kotlin.reflect.full.memberProperties
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@API("api/v2/game/chu3")
|
@API("api/v2/game/chu3")
|
||||||
@@ -33,6 +38,7 @@ class Chusan(
|
|||||||
"trophyIdSub2" to { u, v -> u.trophyIdSub2 = v.int },
|
"trophyIdSub2" to { u, v -> u.trophyIdSub2 = v.int },
|
||||||
"mapIconId" to { u, v -> u.mapIconId = v.int },
|
"mapIconId" to { u, v -> u.mapIconId = v.int },
|
||||||
"voiceId" to { u, v -> u.voiceId = v.int },
|
"voiceId" to { u, v -> u.voiceId = v.int },
|
||||||
|
"characterId" to { u, v -> u.characterId = v.int },
|
||||||
"avatarWear" to { u, v -> u.avatarWear = v.int },
|
"avatarWear" to { u, v -> u.avatarWear = v.int },
|
||||||
"avatarHead" to { u, v -> u.avatarHead = v.int },
|
"avatarHead" to { u, v -> u.avatarHead = v.int },
|
||||||
"avatarFace" to { u, v -> u.avatarFace = v.int },
|
"avatarFace" to { u, v -> u.avatarFace = v.int },
|
||||||
@@ -44,7 +50,7 @@ class Chusan(
|
|||||||
"lastRomVersion" to { u, v -> u.lastRomVersion = v },
|
"lastRomVersion" to { u, v -> u.lastRomVersion = v },
|
||||||
"lastDataVersion" to { u, v -> u.lastDataVersion = v },
|
"lastDataVersion" to { u, v -> u.lastDataVersion = v },
|
||||||
) }
|
) }
|
||||||
override val gettableFields: Set<String> = setOf("level", "playerRating", "characterId")
|
override val gettableFields: Set<String> = setOf("level", "playerRating")
|
||||||
|
|
||||||
override suspend fun userSummary(@RP username: Str, @RP token: String?) = us.cardByName(username) { card ->
|
override suspend fun userSummary(@RP username: Str, @RP token: String?) = us.cardByName(username) { card ->
|
||||||
// Summary values: total plays, player rating, server-wide ranking
|
// Summary values: total plays, player rating, server-wide ranking
|
||||||
@@ -94,6 +100,23 @@ class Chusan(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@API("user-option")
|
||||||
|
override suspend fun userOption(@RP token: String): Any? = us.jwt.auth(token) { u ->
|
||||||
|
rp.userGameOption.findByUser_Card_ExtId(u.ghostCard.extId).getOrNull(0)
|
||||||
|
}
|
||||||
|
@API("user-option-set")
|
||||||
|
override suspend fun userOptionSet(@RP token: String, @RP field: String, @RP value: Int): Any = us.jwt.auth(token) { u ->
|
||||||
|
val gameOptions = rp.userGameOption.findSingleByUser_Card_ExtId(u.ghostCard.extId).getOrNull()
|
||||||
|
val property = UserGameOption::class.memberProperties.filterIsInstance<KMutableProperty1<Any, Any?>>().find{ it.name == field }
|
||||||
|
|
||||||
|
if (property != null && gameOptions != null) {
|
||||||
|
property.setter.call(gameOptions, value)
|
||||||
|
rp.userGameOption.save(gameOptions)
|
||||||
|
200 - "Success"
|
||||||
|
} else
|
||||||
|
400 - "Invalid parameters"
|
||||||
|
}
|
||||||
|
|
||||||
// UserBox related APIs
|
// UserBox related APIs
|
||||||
@API("user-box")
|
@API("user-box")
|
||||||
fun userBox(@RP token: String) = us.jwt.auth(token) {
|
fun userBox(@RP token: String) = us.jwt.auth(token) {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import org.springframework.http.MediaType
|
|||||||
import org.springframework.web.bind.annotation.PostMapping
|
import org.springframework.web.bind.annotation.PostMapping
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.jvm.optionals.getOrNull
|
||||||
|
import kotlin.reflect.KMutableProperty1
|
||||||
|
import kotlin.reflect.full.memberProperties
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@API("api/v2/game/mai2")
|
@API("api/v2/game/mai2")
|
||||||
@@ -145,6 +148,24 @@ class Maimai2(
|
|||||||
SUCCESS
|
SUCCESS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@API("user-option")
|
||||||
|
override suspend fun userOption(@RP token: String) = us.jwt.auth(token) { u ->
|
||||||
|
repos.userOption.findByUser_Card_ExtId(u.ghostCard.extId).getOrNull(0)
|
||||||
|
}
|
||||||
|
@API("user-option-set")
|
||||||
|
override suspend fun userOptionSet(@RP token: String, @RP field: String, @RP value: Int): Any = us.jwt.auth(token) { u ->
|
||||||
|
val gameOptions = repos.userOption.findSingleByUser_Card_ExtId(u.ghostCard.extId).getOrNull()
|
||||||
|
val property = Mai2UserOption::class.memberProperties.filterIsInstance<KMutableProperty1<Any, Any?>>().find{ it.name == field }
|
||||||
|
|
||||||
|
if (property != null && gameOptions != null) {
|
||||||
|
property.setter.call(gameOptions, value)
|
||||||
|
repos.userOption.save(gameOptions)
|
||||||
|
200 - "Success"
|
||||||
|
} else
|
||||||
|
400 - "Invalid parameters"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@API("owned-items")
|
@API("owned-items")
|
||||||
suspend fun ownedItems(@RP token: String) = us.jwt.auth(token) { u ->
|
suspend fun ownedItems(@RP token: String) = us.jwt.auth(token) { u ->
|
||||||
us.cardByName(u.username) { card ->
|
us.cardByName(u.username) { card ->
|
||||||
|
|||||||
@@ -1,15 +1,23 @@
|
|||||||
package icu.samnyan.aqua.net.games.ongeki
|
package icu.samnyan.aqua.net.games.ongeki
|
||||||
|
|
||||||
import ext.API
|
import ext.API
|
||||||
|
import ext.RP
|
||||||
|
import ext.minus
|
||||||
import icu.samnyan.aqua.net.db.AquaUserServices
|
import icu.samnyan.aqua.net.db.AquaUserServices
|
||||||
import icu.samnyan.aqua.net.games.*
|
import icu.samnyan.aqua.net.games.*
|
||||||
import icu.samnyan.aqua.net.utils.*
|
import icu.samnyan.aqua.net.utils.*
|
||||||
import icu.samnyan.aqua.sega.ongeki.OgkUserDataRepo
|
import icu.samnyan.aqua.sega.ongeki.OgkUserDataRepo
|
||||||
import icu.samnyan.aqua.sega.ongeki.OgkUserGeneralDataRepo
|
import icu.samnyan.aqua.sega.ongeki.OgkUserGeneralDataRepo
|
||||||
import icu.samnyan.aqua.sega.ongeki.OgkUserMusicDetailRepo
|
import icu.samnyan.aqua.sega.ongeki.OgkUserMusicDetailRepo
|
||||||
|
import icu.samnyan.aqua.sega.ongeki.OgkUserOptionRepo
|
||||||
import icu.samnyan.aqua.sega.ongeki.OgkUserPlaylogRepo
|
import icu.samnyan.aqua.sega.ongeki.OgkUserPlaylogRepo
|
||||||
import icu.samnyan.aqua.sega.ongeki.model.UserData
|
import icu.samnyan.aqua.sega.ongeki.model.UserData
|
||||||
|
import icu.samnyan.aqua.sega.ongeki.model.UserOption
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
import org.springframework.web.bind.annotation.RestController
|
import org.springframework.web.bind.annotation.RestController
|
||||||
|
import kotlin.jvm.optionals.getOrNull
|
||||||
|
import kotlin.reflect.KMutableProperty1
|
||||||
|
import kotlin.reflect.full.memberProperties
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@API("api/v2/game/ongeki")
|
@API("api/v2/game/ongeki")
|
||||||
@@ -18,7 +26,8 @@ class Ongeki(
|
|||||||
override val playlogRepo: OgkUserPlaylogRepo,
|
override val playlogRepo: OgkUserPlaylogRepo,
|
||||||
override val userDataRepo: OgkUserDataRepo,
|
override val userDataRepo: OgkUserDataRepo,
|
||||||
override val userMusicRepo: OgkUserMusicDetailRepo,
|
override val userMusicRepo: OgkUserMusicDetailRepo,
|
||||||
val userGeneralDataRepository: OgkUserGeneralDataRepo
|
val userGeneralDataRepository: OgkUserGeneralDataRepo,
|
||||||
|
val userOptionRepo: OgkUserOptionRepo
|
||||||
): GameApiController<UserData>("ongeki", UserData::class) {
|
): GameApiController<UserData>("ongeki", UserData::class) {
|
||||||
override suspend fun trend(username: String) = us.cardByName(username) { card ->
|
override suspend fun trend(username: String) = us.cardByName(username) { card ->
|
||||||
findTrend(playlogRepo.findByUser_Card_ExtId(card.extId)
|
findTrend(playlogRepo.findByUser_Card_ExtId(card.extId)
|
||||||
@@ -45,4 +54,21 @@ class Ongeki(
|
|||||||
|
|
||||||
genericUserSummary(card, ratingComposition)
|
genericUserSummary(card, ratingComposition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@API("user-option")
|
||||||
|
override suspend fun userOption(@RP token: String) = us.jwt.auth(token) { u ->
|
||||||
|
userOptionRepo.findByUser_Card_ExtId(u.ghostCard.extId).getOrNull(0)
|
||||||
|
}
|
||||||
|
@API("user-option-set")
|
||||||
|
override suspend fun userOptionSet(@RP token: String, @RP field: String, @RP value: Int): Any = us.jwt.auth(token) { u ->
|
||||||
|
val gameOptions = userOptionRepo.findSingleByUser_Card_ExtId(u.ghostCard.extId).getOrNull()
|
||||||
|
val property = UserOption::class.memberProperties.filterIsInstance<KMutableProperty1<Any, Any?>>().find{ it.name == field }
|
||||||
|
|
||||||
|
if (property != null && gameOptions != null) {
|
||||||
|
property.setter.call(gameOptions, value)
|
||||||
|
userOptionRepo.save(gameOptions)
|
||||||
|
200 - "Success"
|
||||||
|
} else
|
||||||
|
400 - "Invalid parameters"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user