mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-13 03:07:30 +08:00
[O] More information to frontier endpoint
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
package icu.samnyan.aqua.net
|
package icu.samnyan.aqua.net
|
||||||
|
|
||||||
import ext.API
|
import ext.*
|
||||||
import ext.Doc
|
|
||||||
import ext.RP
|
|
||||||
import ext.minus
|
|
||||||
import icu.samnyan.aqua.sega.general.service.CardService
|
import icu.samnyan.aqua.sega.general.service.CardService
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||||
@@ -24,23 +21,35 @@ class Frontier(
|
|||||||
val cardService: CardService,
|
val cardService: CardService,
|
||||||
val props: FrontierProps
|
val props: FrontierProps
|
||||||
) {
|
) {
|
||||||
fun String.checkFtk() {
|
fun Str.checkFtk() {
|
||||||
if (this != props.ftk) 403 - "Invalid FTK"
|
if (this != props.ftk) 403 - "Invalid FTK"
|
||||||
}
|
}
|
||||||
|
|
||||||
@API("/register-card")
|
@API("/register-card")
|
||||||
@Doc("Register a new card by access code", "Success message")
|
@Doc("Register a new card by access code", "Card information")
|
||||||
suspend fun registerCard(@RP ftk: String, @RP accessCode: String): Any {
|
suspend fun registerCard(@RP ftk: Str, @RP accessCode: Str): Any {
|
||||||
ftk.checkFtk()
|
ftk.checkFtk()
|
||||||
|
|
||||||
return cardService.registerByAccessCode(accessCode)
|
if (accessCode.length != 20) 400 - "Invalid access code"
|
||||||
|
if (!accessCode.startsWith("9900")) 400 - "Frontier access code must start with 9900"
|
||||||
|
if (async { cardService.cardRepo.findByLuid(accessCode) }.isPresent) 400 - "Card already registered"
|
||||||
|
|
||||||
|
val card = async { cardService.registerByAccessCode(accessCode) }
|
||||||
|
return mapOf(
|
||||||
|
"card" to card,
|
||||||
|
"id" to card.extId // Expose hidden ID
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@API("/lookup-card")
|
@API("/lookup-card")
|
||||||
@Doc("Lookup a card by access code", "Card information")
|
@Doc("Lookup a card by access code", "Card information")
|
||||||
suspend fun lookupCard(@RP ftk: String, @RP accessCode: String): Any {
|
suspend fun lookupCard(@RP ftk: Str, @RP accessCode: Str): Any {
|
||||||
ftk.checkFtk()
|
ftk.checkFtk()
|
||||||
|
|
||||||
return cardService.tryLookup(accessCode) ?: (404 - "Card not found")
|
val card = cardService.tryLookup(accessCode) ?: (404 - "Card not found")
|
||||||
|
return mapOf(
|
||||||
|
"card" to card,
|
||||||
|
"id" to card.extId // Expose hidden ID
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user