add logic for registration
This commit is contained in:
parent
29ee9377ac
commit
3ffa81cb9b
@ -1,9 +1,10 @@
|
||||
package org.example.data
|
||||
|
||||
import org.example.data.model.UserDTO
|
||||
import org.example.domain.request.RegistrationRequest
|
||||
|
||||
interface UserRepository {
|
||||
fun addUser()
|
||||
fun addUser(registrationRequest: RegistrationRequest): UserDTO
|
||||
fun removeUserById(userId: Int): Boolean
|
||||
fun updateUserById(userId: Int, updatedUser: UserDTO): UserDTO
|
||||
fun getAllUsers(): List<UserDTO>
|
||||
|
@ -1,12 +1,21 @@
|
||||
package org.example.data
|
||||
|
||||
import org.example.data.model.UserDTO
|
||||
import org.example.domain.request.RegistrationRequest
|
||||
|
||||
class UserRepositoryImpl: UserRepository {
|
||||
private val userSource: MutableList<UserDTO> = userList.toMutableList()
|
||||
|
||||
override fun addUser() {
|
||||
TODO("Not yet implemented")
|
||||
|
||||
override fun addUser(registrationRequest: RegistrationRequest): UserDTO {
|
||||
val newUser = UserDTO(
|
||||
userId = userSource.size + 1,
|
||||
email = registrationRequest.email,
|
||||
firstName = registrationRequest.firstName,
|
||||
password = registrationRequest.password
|
||||
)
|
||||
userSource.add(newUser)
|
||||
return newUser
|
||||
}
|
||||
|
||||
override fun removeUserById(userId: Int): Boolean {
|
||||
|
@ -1,11 +1,12 @@
|
||||
package org.example.domain
|
||||
|
||||
import org.example.domain.request.AuthorizeRequest
|
||||
import org.example.domain.request.RegistrationRequest
|
||||
import org.example.domain.response.UserResponse
|
||||
|
||||
interface UserUseCase {
|
||||
fun authorize(authorizeRequest: AuthorizeRequest): UserResponse
|
||||
fun registration()
|
||||
fun registration(registrationRequest: RegistrationRequest): UserResponse
|
||||
fun changePassword()
|
||||
fun changeProfile()
|
||||
}
|
@ -2,6 +2,7 @@ package org.example.domain
|
||||
|
||||
import org.example.data.UserRepository
|
||||
import org.example.domain.request.AuthorizeRequest
|
||||
import org.example.domain.request.RegistrationRequest
|
||||
import org.example.domain.response.UserResponse
|
||||
|
||||
class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
|
||||
@ -19,10 +20,19 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
|
||||
return UserDtoToUserResponse(findUser)
|
||||
}
|
||||
|
||||
override fun registration() {
|
||||
TODO("Not yet implemented")
|
||||
override fun registration(registrationRequest: RegistrationRequest): UserResponse {
|
||||
//уникальность почты
|
||||
val isUnique = userRepository.getAllUsers().firstOrNull{
|
||||
it.email == registrationRequest.email
|
||||
} == null
|
||||
require(isUnique){
|
||||
"Такая почта уже существует"
|
||||
}
|
||||
userRepository.addUser()
|
||||
}
|
||||
|
||||
|
||||
|
||||
override fun changePassword() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
7
src/main/kotlin/domain/request/RegistrationRequest.kt
Normal file
7
src/main/kotlin/domain/request/RegistrationRequest.kt
Normal file
@ -0,0 +1,7 @@
|
||||
package org.example.domain.request
|
||||
|
||||
data class RegistrationRequest (
|
||||
val email: String,
|
||||
val password: String,
|
||||
val firstName: String
|
||||
)
|
@ -6,10 +6,12 @@ import org.example.domain.response.UserResponse
|
||||
|
||||
class UserUI(private val userUseCase: UserUseCase) {
|
||||
fun authorize(){
|
||||
println("Введите почту")
|
||||
val email = readlnOrNull()
|
||||
checkNotNull(email){
|
||||
"Почта не должна отсутствовать"
|
||||
}
|
||||
println("Введите пароль")
|
||||
val password = readlnOrNull()
|
||||
checkNotNull(password){
|
||||
"Пароль не должен отсутствовать"
|
||||
@ -18,10 +20,10 @@ class UserUI(private val userUseCase: UserUseCase) {
|
||||
email = email,
|
||||
password = password,)
|
||||
val user = userUseCase.authorize(authorizeRequest)
|
||||
println(UserResponseToString(user))
|
||||
println(userResponseToString(user))
|
||||
}
|
||||
|
||||
fun UserResponseToString(userResponse: UserResponse): String{
|
||||
private fun userResponseToString(userResponse: UserResponse): String{
|
||||
val printOutput = StringBuilder()
|
||||
printOutput.append("Ваша почта ${userResponse.email}")
|
||||
printOutput.appendLine()
|
||||
|
Loading…
Reference in New Issue
Block a user