[+] Add @ API macro

This commit is contained in:
Azalea
2024-02-20 15:46:48 -05:00
parent befa7d0e8e
commit 0567e0f251
5 changed files with 17 additions and 12 deletions

View File

@@ -14,14 +14,14 @@ import org.springframework.web.bind.annotation.RestController
import kotlin.jvm.optionals.getOrNull
@RestController
@RequestMapping("/api/v2/card")
@API("/api/v2/card")
class CardController(
val userRepo: AquaNetUserRepo,
val jwt: JWT,
val cardService: CardService,
val cardSummary: CardSummary,
) {
@RequestMapping("/summary")
@API("/summary")
suspend fun summary(@RP cardId: Str): Any
{
val card = cardService.tryLookup(cardId) ?: (404 - "Card not found")

View File

@@ -21,7 +21,7 @@ import java.time.LocalDateTime
import java.util.Random
@RestController
@RequestMapping("/api/v2/user")
@API("/api/v2/user")
class UserRegistrar(
val userRepo: AquaNetUserRepo,
val hasher: PasswordEncoder,
@@ -42,7 +42,7 @@ class UserRegistrar(
/**
* Register a new user
*/
@PostMapping("/register")
@API("/register")
suspend fun register(
@RP username: Str, @RP email: Str, @RP password: Str, @RP turnstile: Str,
request: HttpServletRequest
@@ -106,7 +106,7 @@ class UserRegistrar(
return mapOf("success" to true)
}
@PostMapping("/login")
@API("/login")
suspend fun login(
@RP email: Str, @RP password: Str, @RP turnstile: Str,
request: HttpServletRequest
@@ -127,7 +127,7 @@ class UserRegistrar(
return mapOf("token" to token)
}
@PostMapping("/confirm-email")
@API("/confirm-email")
suspend fun confirmEmail(@RP token: Str): Any {
// Find the confirmation
val confirmation = async { confirmationRepo.findByToken(token) }
@@ -141,9 +141,9 @@ class UserRegistrar(
// Confirm the email
async { userRepo.save(confirmation.aquaNetUser.apply { emailConfirmed = true }) }
return mapOf("success" to true)
return SUCCESS
}
@PostMapping("/me")
@API("/me")
suspend fun getUser(@RP token: Str) = jwt.auth(token)
}

View File

@@ -5,6 +5,9 @@ import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
val SUCCESS = ResponseEntity.ok().body(mapOf("status" to "ok"))
class ApiException(val code: Int, message: Str) : RuntimeException(message)
@ControllerAdvice