Adds validation and error handling to signup
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user