more files
This commit is contained in:
parent
4cbe9c453e
commit
a4e6a081f1
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
23
src/Main.kt
23
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)
|
||||
}
|
6
src/data/models/AddUserRequest.kt
Normal file
6
src/data/models/AddUserRequest.kt
Normal file
@ -0,0 +1,6 @@
|
||||
package data.models
|
||||
|
||||
data class AddUserRequest(val firstName:String,
|
||||
val lastName: String,
|
||||
val password:String,
|
||||
val email:String)
|
@ -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)
|
||||
|
22
src/data/repository/NewUserRepositoryImpl.kt
Normal file
22
src/data/repository/NewUserRepositoryImpl.kt
Normal file
@ -0,0 +1,22 @@
|
||||
package data.repository
|
||||
|
||||
import data.models.AddUserRequest
|
||||
import data.models.User
|
||||
|
||||
class NewUserRepositoryImpl:UserRepository {
|
||||
override fun getAllUsers(): List<User> {
|
||||
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")
|
||||
}
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
package data.repository
|
||||
|
||||
import data.models.AddUserRequest
|
||||
import data.models.User
|
||||
|
||||
interface UserRepository {
|
||||
fun getAllUsers(): List<User>
|
||||
fun addUser(user: User): Boolean
|
||||
fun addUser(newUser: AddUserRequest): User
|
||||
fun removeUserById(id: Int): Boolean
|
||||
fun updateUser(id:Int, newUser: User): Boolean
|
||||
}
|
@ -1,21 +1,30 @@
|
||||
package data.repository
|
||||
|
||||
import data.models.AddUserRequest
|
||||
import data.models.User
|
||||
|
||||
class UserRepositoryImpl : UserRepository {
|
||||
private val _users = mutableListOf<User>(
|
||||
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<User> {
|
||||
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
|
||||
}
|
||||
}
|
10
src/domain/AuthUseCase.kt
Normal file
10
src/domain/AuthUseCase.kt
Normal file
@ -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
|
||||
}
|
34
src/domain/AuthUseCaseImpl.kt
Normal file
34
src/domain/AuthUseCaseImpl.kt
Normal file
@ -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
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
3
src/domain/models/AuthorizeRequest.kt
Normal file
3
src/domain/models/AuthorizeRequest.kt
Normal file
@ -0,0 +1,3 @@
|
||||
package domain.models
|
||||
|
||||
data class AuthorizeRequest(val email:String, val password:String)
|
5
src/domain/models/RegistrationRequest.kt
Normal file
5
src/domain/models/RegistrationRequest.kt
Normal file
@ -0,0 +1,5 @@
|
||||
package domain.models
|
||||
|
||||
data class RegistrationRequest(val email:String,
|
||||
val name:String,
|
||||
val password:String)
|
15
src/domain/models/User.kt
Normal file
15
src/domain/models/User.kt
Normal file
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user