mirror of https://github.com/hykilpikonna/AquaDX
[+] More extensions
parent
3d503971ae
commit
361b251952
|
@ -1,7 +1,34 @@
|
||||||
package ext
|
package ext
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam
|
||||||
import org.springframework.web.server.ResponseStatusException
|
import org.springframework.web.server.ResponseStatusException
|
||||||
|
import io.ktor.client.*
|
||||||
|
import io.ktor.client.engine.cio.*
|
||||||
|
import io.ktor.client.plugins.contentnegotiation.*
|
||||||
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
|
|
||||||
|
typealias RP = RequestParam
|
||||||
|
typealias RB = RequestBody
|
||||||
|
typealias RH = RequestHeader
|
||||||
|
typealias Str = String
|
||||||
|
typealias Bool = Boolean
|
||||||
|
|
||||||
// Make it easier to throw a ResponseStatusException
|
// Make it easier to throw a ResponseStatusException
|
||||||
operator fun HttpStatus.invoke(message: String? = null): Nothing = throw ResponseStatusException(this, message ?: this.reasonPhrase)
|
operator fun HttpStatus.invoke(message: String? = null): Nothing = throw ResponseStatusException(this, message ?: this.reasonPhrase)
|
||||||
|
operator fun Int.compareTo(message: String): Int = throw ResponseStatusException(HttpStatus.valueOf(this), message)
|
||||||
|
|
||||||
|
// Email validation
|
||||||
|
// https://www.baeldung.com/java-email-validation-regex
|
||||||
|
val emailRegex = "^(?=.{1,64}@)[\\p{L}0-9_-]+(\\.[\\p{L}0-9_-]+)*@[^-][\\p{L}0-9-]+(\\.[\\p{L}0-9-]+)*(\\.[\\p{L}]{2,})$".toRegex()
|
||||||
|
fun Str.isValidEmail(): Bool = emailRegex.matches(this)
|
||||||
|
|
||||||
|
fun millis() = System.currentTimeMillis()
|
||||||
|
|
||||||
|
val HTTP = HttpClient(CIO) {
|
||||||
|
install(ContentNegotiation) {
|
||||||
|
json()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package icu.samnyan.aqua.api.controller.sega.game.maimai2
|
package icu.samnyan.aqua.api.controller.sega.game.maimai2
|
||||||
|
|
||||||
|
import ext.RP
|
||||||
import ext.invoke
|
import ext.invoke
|
||||||
import icu.samnyan.aqua.sega.maimai2.dao.userdata.UserDataRepository
|
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.UserGeneralDataRepository
|
||||||
|
@ -22,7 +23,7 @@ class Maimai2New(
|
||||||
data class TrendOut(val date: String, val rating: Int, val plays: Int)
|
data class TrendOut(val date: String, val rating: Int, val plays: Int)
|
||||||
|
|
||||||
@GetMapping("trend")
|
@GetMapping("trend")
|
||||||
fun trend(@RequestParam userId: Long): List<TrendOut> {
|
fun trend(@RP userId: Long): List<TrendOut> {
|
||||||
// O(n log n) sort
|
// O(n log n) sort
|
||||||
val d = userPlaylogRepository.findByUser_Card_ExtId(userId).sortedBy { it.playDate }.toList()
|
val d = userPlaylogRepository.findByUser_Card_ExtId(userId).sortedBy { it.playDate }.toList()
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ class Maimai2New(
|
||||||
97.0 to "S").map { (k, v) -> (k * 10000).toInt() to v }
|
97.0 to "S").map { (k, v) -> (k * 10000).toInt() to v }
|
||||||
|
|
||||||
@GetMapping("user-summary")
|
@GetMapping("user-summary")
|
||||||
fun userSummary(@RequestParam userId: Long): Map<String, Any> {
|
fun userSummary(@RP userId: Long): Map<String, Any> {
|
||||||
// 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 = userDataRepository.findByCard_ExtId(userId).getOrNull() ?: NOT_FOUND()
|
val user = userDataRepository.findByCard_ExtId(userId).getOrNull() ?: NOT_FOUND()
|
||||||
|
|
Loading…
Reference in New Issue