From 82f573e1a17ce4b5dc5c0fe618c7842a0086b525 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 6 Mar 2024 10:42:31 -0500 Subject: [PATCH] [O] More information to frontier endpoint --- .../java/icu/samnyan/aqua/net/Frontier.kt | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/icu/samnyan/aqua/net/Frontier.kt b/src/main/java/icu/samnyan/aqua/net/Frontier.kt index 306aa246..d4c558b4 100644 --- a/src/main/java/icu/samnyan/aqua/net/Frontier.kt +++ b/src/main/java/icu/samnyan/aqua/net/Frontier.kt @@ -1,9 +1,6 @@ package icu.samnyan.aqua.net -import ext.API -import ext.Doc -import ext.RP -import ext.minus +import ext.* import icu.samnyan.aqua.sega.general.service.CardService import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty import org.springframework.boot.context.properties.ConfigurationProperties @@ -24,23 +21,35 @@ class Frontier( val cardService: CardService, val props: FrontierProps ) { - fun String.checkFtk() { + fun Str.checkFtk() { if (this != props.ftk) 403 - "Invalid FTK" } @API("/register-card") - @Doc("Register a new card by access code", "Success message") - suspend fun registerCard(@RP ftk: String, @RP accessCode: String): Any { + @Doc("Register a new card by access code", "Card information") + suspend fun registerCard(@RP ftk: Str, @RP accessCode: Str): Any { 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") @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() - 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 + ) } }