commit 4cbe9c453e69279db84a0f90c2c8404a7a3df5ef Author: KP9lK Date: Mon Nov 11 23:10:52 2024 +0300 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..8226e53 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..a9b3aa2 --- /dev/null +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..952b1db --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c1dbb9e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ex1.iml b/ex1.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/ex1.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Main.kt b/src/Main.kt new file mode 100644 index 0000000..f24b015 --- /dev/null +++ b/src/Main.kt @@ -0,0 +1,36 @@ +import data.models.User +import data.repository.UserRepository +import data.repository.UserRepositoryImpl + +fun main() { + val repository = UserRepositoryImpl() + + + while (true) { + println("1.Вывести пользователей\n2.Добавить пользователя") + when (readln().toInt()) { + 1 -> printAllUsers(repository) + 2 -> addUser(repository) + else -> break + } + } + +} + +fun printAllUsers(userRepository: UserRepository) { + userRepository.getAllUsers().forEach { user -> + println("${user.id} ${user.email} ${user.lastName} ${user.firstName}") + } +} + +fun addUser(userRepository: UserRepository){ + println("Введите почту") + val email = readln() + 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) +} \ No newline at end of file diff --git a/src/data/models/User.kt b/src/data/models/User.kt new file mode 100644 index 0000000..edd1d4c --- /dev/null +++ b/src/data/models/User.kt @@ -0,0 +1,6 @@ +package data.models + +data class User(val id: Int, + val firstName: String, + val lastName: String, + val email:String) diff --git a/src/data/repository/UserRepository.kt b/src/data/repository/UserRepository.kt new file mode 100644 index 0000000..db45e89 --- /dev/null +++ b/src/data/repository/UserRepository.kt @@ -0,0 +1,10 @@ +package data.repository + +import data.models.User + +interface UserRepository { + fun getAllUsers(): List + fun addUser(user: User): Boolean + 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 new file mode 100644 index 0000000..dcf46ee --- /dev/null +++ b/src/data/repository/UserRepositoryImpl.kt @@ -0,0 +1,28 @@ +package data.repository + +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"), + ) + override fun getAllUsers(): List { + return _users + } + + override fun addUser(user: User): Boolean { + val result = _users.add(user) + return result + } + + 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