diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Main.kt b/src/Main.kt
index f24b015..6017ff6 100644
--- a/src/Main.kt
+++ b/src/Main.kt
@@ -1,16 +1,22 @@
+import domain.AuthUseCaseImpl
import data.models.User
+import data.repository.NewUserRepositoryImpl
import data.repository.UserRepository
import data.repository.UserRepositoryImpl
+import domain.AuthUseCase
+import domain.models.RegistrationRequest
fun main() {
val repository = UserRepositoryImpl()
+ val useCase = AuthUseCaseImpl(repository)
while (true) {
- println("1.Вывести пользователей\n2.Добавить пользователя")
+
+ println("1.Вывести пользователей\n2.Регистрация пользователя")
when (readln().toInt()) {
1 -> printAllUsers(repository)
- 2 -> addUser(repository)
+ 2 -> addUser(useCase)
else -> break
}
}
@@ -23,14 +29,13 @@ fun printAllUsers(userRepository: UserRepository) {
}
}
-fun addUser(userRepository: UserRepository){
+fun addUser(useCase: AuthUseCase){
println("Введите почту")
val email = readln()
- println("Введите имя")
+ println("Введите Имя Фамилию")
val firstName = readln()
- println("Введите фамилию")
- val lastName = readln()
- val id = userRepository.getAllUsers().count() + 1
- val user = User(email = email, firstName = firstName, lastName = lastName, id = id)
- userRepository.addUser(user)
+ println("Введите пароль")
+ val password = readln()
+ val user = RegistrationRequest(email = email, name = firstName, password = password)
+ useCase.registration(user)
}
\ No newline at end of file
diff --git a/src/data/models/AddUserRequest.kt b/src/data/models/AddUserRequest.kt
new file mode 100644
index 0000000..e2a1f88
--- /dev/null
+++ b/src/data/models/AddUserRequest.kt
@@ -0,0 +1,6 @@
+package data.models
+
+data class AddUserRequest(val firstName:String,
+ val lastName: String,
+ val password:String,
+ val email:String)
diff --git a/src/data/models/User.kt b/src/data/models/User.kt
index edd1d4c..357876c 100644
--- a/src/data/models/User.kt
+++ b/src/data/models/User.kt
@@ -3,4 +3,5 @@ package data.models
data class User(val id: Int,
val firstName: String,
val lastName: String,
+ val password: String,
val email:String)
diff --git a/src/data/repository/NewUserRepositoryImpl.kt b/src/data/repository/NewUserRepositoryImpl.kt
new file mode 100644
index 0000000..34313f5
--- /dev/null
+++ b/src/data/repository/NewUserRepositoryImpl.kt
@@ -0,0 +1,22 @@
+package data.repository
+
+import data.models.AddUserRequest
+import data.models.User
+
+class NewUserRepositoryImpl:UserRepository {
+ override fun getAllUsers(): List {
+ TODO("Not yet implemented")
+ }
+
+ override fun addUser(newUser: AddUserRequest): User {
+ TODO("Not yet implemented")
+ }
+
+ override fun removeUserById(id: Int): Boolean {
+ TODO("Not yet implemented")
+ }
+
+ override fun updateUser(id: Int, newUser: User): Boolean {
+ TODO("Not yet implemented")
+ }
+}
\ No newline at end of file
diff --git a/src/data/repository/UserRepository.kt b/src/data/repository/UserRepository.kt
index db45e89..93cb82b 100644
--- a/src/data/repository/UserRepository.kt
+++ b/src/data/repository/UserRepository.kt
@@ -1,10 +1,11 @@
package data.repository
+import data.models.AddUserRequest
import data.models.User
interface UserRepository {
fun getAllUsers(): List
- fun addUser(user: User): Boolean
+ fun addUser(newUser: AddUserRequest): User
fun removeUserById(id: Int): Boolean
fun updateUser(id:Int, newUser: User): Boolean
}
\ No newline at end of file
diff --git a/src/data/repository/UserRepositoryImpl.kt b/src/data/repository/UserRepositoryImpl.kt
index dcf46ee..be61c0d 100644
--- a/src/data/repository/UserRepositoryImpl.kt
+++ b/src/data/repository/UserRepositoryImpl.kt
@@ -1,21 +1,30 @@
package data.repository
+import data.models.AddUserRequest
import data.models.User
class UserRepositoryImpl : UserRepository {
private val _users = mutableListOf(
- User(id = 1, lastName = "Ivanov", firstName = "Ivan", email = "ivan@mai.ru"),
- User(id = 2, lastName = "Petrov", firstName = "Petr", email = "petr@mai.ru"),
- User(id = 3, lastName = "Alex", firstName = "Alexandrov", email = "Alex@mai.ru"),
- User(id = 4, lastName = "Kolya", firstName = "Nikolaev", email = "kolya@mai.ru"),
+ User(id = 1, lastName = "Ivanov", firstName = "Ivan", email = "ivan@mai.ru", password = "123"),
+ User(id = 2, lastName = "Petrov", firstName = "Petr", email = "petr@mai.ru", password = "123"),
+ User(id = 3, lastName = "Alex", firstName = "Alexandrov", email = "Alex@mai.ru", password = "123"),
+ User(id = 4, lastName = "Kolya", firstName = "Nikolaev", email = "kolya@mai.ru", password = "123"),
)
+
override fun getAllUsers(): List {
return _users
}
- override fun addUser(user: User): Boolean {
- val result = _users.add(user)
- return result
+ override fun addUser(newUser: AddUserRequest): User
+ {
+ val user = User(id = _users.count() + 1,
+ email = newUser.email,
+ lastName = newUser.lastName,
+ firstName = newUser.firstName,
+ password = newUser.password
+ )
+ _users.add(user)
+ return user
}
override fun removeUserById(id: Int): Boolean {
@@ -23,6 +32,12 @@ class UserRepositoryImpl : UserRepository {
}
override fun updateUser(id: Int, newUser: User): Boolean {
- TODO("Not yet implemented")
+ val userIndex = _users.indexOfFirst { it -> it.id == id }
+ _users[userIndex] = _users[userIndex].copy(
+ firstName = newUser.firstName,
+ lastName = newUser.lastName,
+ email = newUser.email,
+ )
+ return true
}
}
\ No newline at end of file
diff --git a/src/domain/AuthUseCase.kt b/src/domain/AuthUseCase.kt
new file mode 100644
index 0000000..401146d
--- /dev/null
+++ b/src/domain/AuthUseCase.kt
@@ -0,0 +1,10 @@
+package domain
+
+import domain.models.AuthorizeRequest
+import domain.models.RegistrationRequest
+import domain.models.User
+
+interface AuthUseCase {
+ fun authorize(authorizeRequest: AuthorizeRequest): User
+ fun registration(registrationRequest: RegistrationRequest) : User
+}
\ No newline at end of file
diff --git a/src/domain/AuthUseCaseImpl.kt b/src/domain/AuthUseCaseImpl.kt
new file mode 100644
index 0000000..9bba783
--- /dev/null
+++ b/src/domain/AuthUseCaseImpl.kt
@@ -0,0 +1,34 @@
+package domain
+
+import data.models.AddUserRequest
+import data.repository.UserRepository
+import domain.models.AuthorizeRequest
+import domain.models.RegistrationRequest
+import domain.models.User
+
+class AuthUseCaseImpl(private val repository: UserRepository): AuthUseCase {
+ override fun authorize(authorizeRequest: AuthorizeRequest): User {
+ TODO("Not yet implemented")
+ }
+
+ override fun registration(registrationRequest: RegistrationRequest): User {
+ val name = registrationRequest.name.split(' ')
+ val user = AddUserRequest(
+ email = registrationRequest.email,
+ password = registrationRequest.password,
+ firstName = name[0],
+ lastName = name[1]
+ )
+ val result = repository.addUser(user)
+ return User(
+ id = result.id,
+ lastName = result.lastName,
+ firstName = result.firstName,
+ email = result.email,
+ password = result.password
+ )
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/domain/models/AuthorizeRequest.kt b/src/domain/models/AuthorizeRequest.kt
new file mode 100644
index 0000000..976f919
--- /dev/null
+++ b/src/domain/models/AuthorizeRequest.kt
@@ -0,0 +1,3 @@
+package domain.models
+
+data class AuthorizeRequest(val email:String, val password:String)
diff --git a/src/domain/models/RegistrationRequest.kt b/src/domain/models/RegistrationRequest.kt
new file mode 100644
index 0000000..b34c6bd
--- /dev/null
+++ b/src/domain/models/RegistrationRequest.kt
@@ -0,0 +1,5 @@
+package domain.models
+
+data class RegistrationRequest(val email:String,
+ val name:String,
+ val password:String)
\ No newline at end of file
diff --git a/src/domain/models/User.kt b/src/domain/models/User.kt
new file mode 100644
index 0000000..e6f1bb5
--- /dev/null
+++ b/src/domain/models/User.kt
@@ -0,0 +1,15 @@
+package domain.models
+
+data class User(val id: Int,
+ val firstName: String,
+ val lastName: String,
+ val email:String,
+ var password:String
+ )
+{
+fun resetPassword(password: String, confirmedPassword:String):Boolean{
+if(password != confirmedPassword) return false
+ this.password = password
+ return true
+}
+}