From dd55e336e4e39c52c83c2fdba04281f356888521 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 22 Feb 2024 18:20:54 -0500 Subject: [PATCH] [+] API for unlinking --- .../java/icu/samnyan/aqua/net/CardController.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/icu/samnyan/aqua/net/CardController.kt b/src/main/java/icu/samnyan/aqua/net/CardController.kt index 73d7c04e..618965c7 100644 --- a/src/main/java/icu/samnyan/aqua/net/CardController.kt +++ b/src/main/java/icu/samnyan/aqua/net/CardController.kt @@ -74,6 +74,21 @@ class CardController( SUCCESS } + + @API("/unlink") + suspend fun unlink(@RP token: Str, @RP cardId: Str) = jwt.auth(token) { u -> + // Try to look up the card + val card = cardService.tryLookup(cardId) ?: (404 - "Card not found") + + // If the card is not bound to the user + if (card.aquaUser != u) 400 - "Card not bound to user" + + // Unbind the card + card.aquaUser = null + async { cardRepository.save(card) } + + SUCCESS + } } @Service