Adds basic hunter signup endpoint
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
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.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
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())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.converter
|
||||
|
||||
import net.halfbinary.scavengerhuntapi.model.domain.Hunter
|
||||
import net.halfbinary.scavengerhuntapi.model.record.HunterRecord
|
||||
import net.halfbinary.scavengerhuntapi.model.request.HunterSignupRequest
|
||||
|
||||
fun HunterSignupRequest.toDomain(): Hunter {
|
||||
return Hunter(
|
||||
email = email,
|
||||
name = name,
|
||||
password = password,
|
||||
isAdmin = false
|
||||
)
|
||||
}
|
||||
|
||||
fun Hunter.toRecord(): HunterRecord {
|
||||
return HunterRecord(id, email, name, password, isAdmin)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.domain
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
data class Hunter(
|
||||
val id: UUID = UUID.randomUUID(),
|
||||
val email: String,
|
||||
val name: String,
|
||||
val password: String,
|
||||
val isAdmin: Boolean
|
||||
)
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.halfbinary.scavengerhuntapi.model.request
|
||||
|
||||
data class HunterSignupRequest(
|
||||
val email: String,
|
||||
val name: String,
|
||||
val password: String
|
||||
)
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.halfbinary.scavengerhuntapi.service
|
||||
|
||||
import net.halfbinary.scavengerhuntapi.model.converter.toRecord
|
||||
import net.halfbinary.scavengerhuntapi.model.domain.Hunter
|
||||
import net.halfbinary.scavengerhuntapi.repository.HunterRepository
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class SignupService(private val hunterRepository: HunterRepository) {
|
||||
fun createNewHunter(hunter: Hunter) {
|
||||
hunterRepository.save(hunter.toRecord())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user