From 4a1077833ed46b5ec275d3d06546a345fcc8752e Mon Sep 17 00:00:00 2001 From: aarbit Date: Tue, 12 May 2026 23:54:08 -0500 Subject: [PATCH] Adds/collects Hunter endpoints and cleans up the code a bit --- .../scavengerhuntapi/controller/AuthController.kt | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/AuthController.kt b/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/AuthController.kt index 92c7cb2..aa7bc09 100644 --- a/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/AuthController.kt +++ b/src/main/kotlin/net/halfbinary/scavengerhuntapi/controller/AuthController.kt @@ -1,6 +1,5 @@ package net.halfbinary.scavengerhuntapi.controller -import jakarta.servlet.http.HttpServletResponse import jakarta.validation.Valid import net.halfbinary.scavengerhuntapi.config.JwtUtil import net.halfbinary.scavengerhuntapi.model.converter.toDomain @@ -13,28 +12,18 @@ import net.halfbinary.scavengerhuntapi.model.response.RefreshResponse import net.halfbinary.scavengerhuntapi.service.LoginService import net.halfbinary.scavengerhuntapi.service.RefreshTokenService import org.springframework.http.ResponseEntity -import org.springframework.security.core.authority.SimpleGrantedAuthority -import org.springframework.security.core.userdetails.User import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController -import java.util.Collections @RestController @RequestMapping("/auth") class AuthController(private val loginService: LoginService, private val jwtUtils: JwtUtil, private val refreshTokenService: RefreshTokenService) { @PostMapping("/login") - fun login(@Valid @RequestBody body: LoginRequest, response: HttpServletResponse): ResponseEntity { + fun login(@Valid @RequestBody body: LoginRequest): ResponseEntity { val result = loginService.login(body.toDomain()) - val hunterAuthorities = - if (result.isAdmin) { - SimpleGrantedAuthority("ROLE_ADMIN") - } else { - SimpleGrantedAuthority("ROLE_USER") - } - val user = User(result.email, result.password, Collections.singleton(hunterAuthorities)) val accessToken = jwtUtils.generateToken(result.email) val refreshToken = refreshTokenService.generateRefreshToken(result.email) val loginResponse = LoginResponse(accessToken, refreshToken) @@ -47,7 +36,7 @@ class AuthController(private val loginService: LoginService, private val jwtUtil } @PostMapping("/logout") - fun logout(@RequestBody body: LogoutRequest, response: HttpServletResponse): ResponseEntity { + fun logout(@RequestBody body: LogoutRequest): ResponseEntity { refreshTokenService.removeToken(body.refreshToken) return ResponseEntity.ok().build() }