Implements Hunt basic create and get, and adds field validation to controllers
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package net.halfbinary.scavengerhuntapi.controller
|
||||
|
||||
import jakarta.validation.Valid
|
||||
import net.halfbinary.scavengerhuntapi.model.HuntId
|
||||
import net.halfbinary.scavengerhuntapi.model.converter.toDomain
|
||||
import net.halfbinary.scavengerhuntapi.model.converter.toResponse
|
||||
import net.halfbinary.scavengerhuntapi.model.request.HuntCreateRequest
|
||||
import net.halfbinary.scavengerhuntapi.model.request.HuntStatus
|
||||
import net.halfbinary.scavengerhuntapi.model.response.HuntResponse
|
||||
import net.halfbinary.scavengerhuntapi.service.HuntService
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@RestController
|
||||
@RequestMapping("hunt")
|
||||
class HuntController(private val huntService: HuntService) {
|
||||
|
||||
@GetMapping("/{id}")
|
||||
fun getHunt(@PathVariable("id") huntId: HuntId): ResponseEntity<HuntResponse> {
|
||||
return ResponseEntity.ok(huntService.getHunt(huntId).toResponse())
|
||||
}
|
||||
|
||||
@GetMapping()
|
||||
fun getAllHunts(@RequestParam status: HuntStatus?): ResponseEntity<List<HuntResponse>> {
|
||||
return ResponseEntity.ok(huntService.getAllHunts(status).map { it.toResponse() })
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
fun createHunt(@Valid @RequestBody huntRequest: HuntCreateRequest): ResponseEntity<HuntResponse> {
|
||||
return ResponseEntity.ok(huntService.createHunt(huntRequest.toDomain()).toResponse())
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package net.halfbinary.scavengerhuntapi.controller
|
||||
|
||||
import jakarta.servlet.http.Cookie
|
||||
import jakarta.servlet.http.HttpServletResponse
|
||||
import jakarta.validation.Valid
|
||||
import net.halfbinary.scavengerhuntapi.model.converter.toDomain
|
||||
import net.halfbinary.scavengerhuntapi.model.converter.toLoginResponse
|
||||
import net.halfbinary.scavengerhuntapi.model.request.LoginRequest
|
||||
@@ -17,7 +18,7 @@ import java.net.URLEncoder
|
||||
@RestController
|
||||
class LoginController(private val loginService: LoginService) {
|
||||
@PostMapping("/login")
|
||||
fun login(@RequestBody body: LoginRequest, response: HttpServletResponse): ResponseEntity<LoginResponse> {
|
||||
fun login(@Valid @RequestBody body: LoginRequest, response: HttpServletResponse): ResponseEntity<LoginResponse> {
|
||||
val result = loginService.login(body.toDomain())
|
||||
val creds = "${result.email}|${result.name}"
|
||||
val encodedCreds = URLEncoder.encode(creds, "UTF-8")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.halfbinary.scavengerhuntapi.controller
|
||||
|
||||
import jakarta.validation.Valid
|
||||
import net.halfbinary.scavengerhuntapi.model.converter.toDomain
|
||||
import net.halfbinary.scavengerhuntapi.model.request.HunterSignupRequest
|
||||
import net.halfbinary.scavengerhuntapi.service.SignupService
|
||||
@@ -11,7 +12,7 @@ import org.springframework.web.bind.annotation.RestController
|
||||
@RestController
|
||||
class SignupController(private val signupService: SignupService) {
|
||||
@PostMapping("/signup")
|
||||
fun hunterSignup(@RequestBody body: HunterSignupRequest): ResponseEntity<Any> {
|
||||
fun hunterSignup(@Valid @RequestBody body: HunterSignupRequest): ResponseEntity<Any> {
|
||||
signupService.createNewHunter(body.toDomain())
|
||||
return ResponseEntity.ok().build()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user