add registration
This commit is contained in:
parent
25cca87bb6
commit
7d2e666e60
@ -1,17 +1,24 @@
|
|||||||
package org.example
|
package org.example
|
||||||
|
|
||||||
import org.example.data.authorize
|
import org.example.data.authorize
|
||||||
|
import org.example.data.registration
|
||||||
import org.example.data.users
|
import org.example.data.users
|
||||||
import org.example.domain.request.UserAuthorizeRequest
|
import org.example.domain.request.UserAuthorizeRequest
|
||||||
|
import org.example.domain.request.UserRegistrationRequest
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
users.forEach {
|
users.forEach {
|
||||||
println(it)
|
println(it)
|
||||||
}
|
}
|
||||||
val email = readlnOrNull()
|
val email = readlnOrNull()
|
||||||
|
val lastname = readlnOrNull()
|
||||||
val password = readlnOrNull()
|
val password = readlnOrNull()
|
||||||
checkNotNull(email)
|
checkNotNull(email)
|
||||||
|
checkNotNull(lastname)
|
||||||
checkNotNull(password)
|
checkNotNull(password)
|
||||||
val user = authorize(UserAuthorizeRequest(email, password))
|
val user = registration(UserRegistrationRequest(lastname, email, password))
|
||||||
println(user)
|
println(user)
|
||||||
|
users.forEach {
|
||||||
|
println(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,19 @@ package org.example.data
|
|||||||
import io.github.serpro69.kfaker.Faker
|
import io.github.serpro69.kfaker.Faker
|
||||||
import org.example.domain.entity.User
|
import org.example.domain.entity.User
|
||||||
import org.example.domain.request.UserAuthorizeRequest
|
import org.example.domain.request.UserAuthorizeRequest
|
||||||
|
import org.example.domain.request.UserRegistrationRequest
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
data class LocalUser(
|
data class LocalUser(
|
||||||
val uuid: UUID,
|
val uuid: UUID,
|
||||||
var lastname: String,
|
var lastname: String,
|
||||||
var firstname: String,
|
var firstname: String? = null,
|
||||||
var email: String,
|
var email: String,
|
||||||
var url: String,
|
var url: String? = null,
|
||||||
var password: String,
|
var password: String,
|
||||||
var phone: String
|
var phone: String? = null
|
||||||
)
|
)
|
||||||
val users = generateUsers(100)
|
val users = generateUsers(100).toMutableList()
|
||||||
fun generateUsers(userCount: Int): List<LocalUser>{
|
fun generateUsers(userCount: Int): List<LocalUser>{
|
||||||
val localUserList = mutableListOf<LocalUser>()
|
val localUserList = mutableListOf<LocalUser>()
|
||||||
val faker = Faker()
|
val faker = Faker()
|
||||||
@ -51,3 +52,17 @@ fun authorize(userAuthorizeRequest: UserAuthorizeRequest): User{
|
|||||||
else throw IllegalArgumentException("Пароли не совпадают")
|
else throw IllegalArgumentException("Пароли не совпадают")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun registration(userRegistrationRequest: UserRegistrationRequest):User{
|
||||||
|
val user = LocalUser(
|
||||||
|
uuid = UUID.randomUUID(),
|
||||||
|
lastname = userRegistrationRequest.lastname,
|
||||||
|
email = userRegistrationRequest.password,
|
||||||
|
password = userRegistrationRequest.password
|
||||||
|
)
|
||||||
|
users.add(user)
|
||||||
|
return User(
|
||||||
|
uuid = user.uuid,
|
||||||
|
lastname = user.lastname,
|
||||||
|
email = user.email
|
||||||
|
)
|
||||||
|
}
|
@ -6,8 +6,8 @@ import kotlin.uuid.Uuid
|
|||||||
data class User(
|
data class User(
|
||||||
val uuid:UUID,
|
val uuid:UUID,
|
||||||
var lastname: String,
|
var lastname: String,
|
||||||
var firstname: String,
|
var firstname: String? = null,
|
||||||
var email: String,
|
var email: String,
|
||||||
var url: String,
|
var url: String? = null,
|
||||||
var phone:String
|
var phone:String? = null
|
||||||
)
|
)
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package org.example.domain.request
|
||||||
|
|
||||||
|
data class UserRegistrationRequest(
|
||||||
|
val lastname:String,
|
||||||
|
val email: String,
|
||||||
|
val password: String
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user