add registration

This commit is contained in:
KP9lKk 2025-01-15 16:17:52 +03:00
parent 25cca87bb6
commit 7d2e666e60
4 changed files with 37 additions and 8 deletions

View File

@ -1,17 +1,24 @@
package org.example
import org.example.data.authorize
import org.example.data.registration
import org.example.data.users
import org.example.domain.request.UserAuthorizeRequest
import org.example.domain.request.UserRegistrationRequest
fun main() {
users.forEach {
println(it)
}
val email = readlnOrNull()
val lastname = readlnOrNull()
val password = readlnOrNull()
checkNotNull(email)
checkNotNull(lastname)
checkNotNull(password)
val user = authorize(UserAuthorizeRequest(email, password))
val user = registration(UserRegistrationRequest(lastname, email, password))
println(user)
users.forEach {
println(it)
}
}

View File

@ -3,18 +3,19 @@ package org.example.data
import io.github.serpro69.kfaker.Faker
import org.example.domain.entity.User
import org.example.domain.request.UserAuthorizeRequest
import org.example.domain.request.UserRegistrationRequest
import java.util.*
data class LocalUser(
val uuid: UUID,
var lastname: String,
var firstname: String,
var firstname: String? = null,
var email: String,
var url: String,
var url: String? = null,
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>{
val localUserList = mutableListOf<LocalUser>()
val faker = Faker()
@ -51,3 +52,17 @@ fun authorize(userAuthorizeRequest: UserAuthorizeRequest): User{
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
)
}

View File

@ -6,8 +6,8 @@ import kotlin.uuid.Uuid
data class User(
val uuid:UUID,
var lastname: String,
var firstname: String,
var firstname: String? = null,
var email: String,
var url: String,
var phone:String
var url: String? = null,
var phone:String? = null
)

View File

@ -0,0 +1,7 @@
package org.example.domain.request
data class UserRegistrationRequest(
val lastname:String,
val email: String,
val password: String
)