Adds validation and error handling to signup

This commit is contained in:
2025-12-05 00:15:20 -06:00
parent 8b808bfd34
commit 302feeab1e
6 changed files with 30 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package net.halfbinary.scavengerhuntapi.controller
import net.halfbinary.scavengerhuntapi.model.converter.toDomain
import net.halfbinary.scavengerhuntapi.model.request.HunterSignupRequest
import net.halfbinary.scavengerhuntapi.service.SignupService
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RestController
@@ -10,7 +11,13 @@ import org.springframework.web.bind.annotation.RestController
@RestController
class SignupController(private val signupService: SignupService) {
@PostMapping("/signup")
fun hunterSignup(@RequestBody body: HunterSignupRequest) {
signupService.createNewHunter(body.toDomain())
fun hunterSignup(@RequestBody body: HunterSignupRequest): ResponseEntity<Any> {
try {
signupService.createNewHunter(body.toDomain())
return ResponseEntity.ok().build()
} catch (e: RuntimeException) {
return ResponseEntity.badRequest().body(e.message)
}
}
}