Fix register
This commit is contained in:
parent
b8e6c4b7ca
commit
2af0930675
@ -20,6 +20,7 @@ import org.http4k.routing.routes
|
|||||||
|
|
||||||
data class Message(val msg: String)
|
data class Message(val msg: String)
|
||||||
data class Login(val username: String, val password: String)
|
data class Login(val username: String, val password: String)
|
||||||
|
data class Register(val username: String, val password: String)
|
||||||
|
|
||||||
class UserRoutes(
|
class UserRoutes(
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
@ -30,6 +31,7 @@ class UserRoutes(
|
|||||||
private val userLens = Body.auto<User>("user", ContentNegotiation.StrictNoDirective).toLens()
|
private val userLens = Body.auto<User>("user", ContentNegotiation.StrictNoDirective).toLens()
|
||||||
private val msgLens = Body.auto<Message>().toLens()
|
private val msgLens = Body.auto<Message>().toLens()
|
||||||
private val loginLens = Body.auto<Login>().toLens()
|
private val loginLens = Body.auto<Login>().toLens()
|
||||||
|
private val registerLens = Body.auto<Register>().toLens()
|
||||||
private val idLens = Path.long().map { UserId(it) }.of("id")
|
private val idLens = Path.long().map { UserId(it) }.of("id")
|
||||||
private val userIdLens = RequestContextKey.required<UserId>(ctx, "auth")
|
private val userIdLens = RequestContextKey.required<UserId>(ctx, "auth")
|
||||||
|
|
||||||
@ -37,7 +39,8 @@ class UserRoutes(
|
|||||||
|
|
||||||
override fun get() = routes(
|
override fun get() = routes(
|
||||||
"/user" bind POST to {
|
"/user" bind POST to {
|
||||||
userRepository.create(userLens(it))
|
val (username, password) = registerLens(it)
|
||||||
|
userRepository.create(User(null, username, password))
|
||||||
Response.ok().with(msgLens of Message("created"))
|
Response.ok().with(msgLens of Message("created"))
|
||||||
},
|
},
|
||||||
"/user/{id}" bind GET to {
|
"/user/{id}" bind GET to {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user