From 7e66b88679a0f203697452944dc5e105c0854bd9 Mon Sep 17 00:00:00 2001 From: KP9lKk Date: Thu, 30 Jan 2025 10:48:04 +0300 Subject: [PATCH] add shoes --- .idea/misc.xml | 2 +- src/main/kotlin/Main.kt | 11 ++-- src/main/kotlin/data/ShoesRepository.kt | 7 ++ src/main/kotlin/data/ShoesRepositoryImpl.kt | 19 ++++++ src/main/kotlin/data/localDataSource.kt | 11 ++++ src/main/kotlin/data/model/ShoesDTO.kt | 9 +++ src/main/kotlin/ui/MainMenuUI.kt | 72 +++++++++++++++++++++ src/main/kotlin/ui/UserUI.kt | 5 ++ 8 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 src/main/kotlin/data/ShoesRepository.kt create mode 100644 src/main/kotlin/data/ShoesRepositoryImpl.kt create mode 100644 src/main/kotlin/data/model/ShoesDTO.kt create mode 100644 src/main/kotlin/ui/MainMenuUI.kt diff --git a/.idea/misc.xml b/.idea/misc.xml index 5cd9a10..c6674f3 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,7 +1,7 @@ - + \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 944ca99..9d734eb 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,15 +1,18 @@ package org.example -import org.example.data.UserRepository import org.example.data.UserRepositoryImpl import org.example.domain.UserUseCaseImpl +import org.example.ui.MainMenuUI import org.example.ui.UserUI + +//class_student +//localuser - где нет rtk +//844SystemUser fun main() { val userRepository = UserRepositoryImpl() val userUseCase = UserUseCaseImpl(userRepository) val userUI = UserUI(userUseCase) - userUI.authorize() - userUI.changePassword() - userUI.authorize() + val mainMenuUI = MainMenuUI(userUI) + mainMenuUI.displayStartMenu() } \ No newline at end of file diff --git a/src/main/kotlin/data/ShoesRepository.kt b/src/main/kotlin/data/ShoesRepository.kt new file mode 100644 index 0000000..6d199e3 --- /dev/null +++ b/src/main/kotlin/data/ShoesRepository.kt @@ -0,0 +1,7 @@ +package org.example.data + +interface ShoesRepository { + fun addShoes() + fun getAllShoes() + fun removeShoes() +} \ No newline at end of file diff --git a/src/main/kotlin/data/ShoesRepositoryImpl.kt b/src/main/kotlin/data/ShoesRepositoryImpl.kt new file mode 100644 index 0000000..1267c8d --- /dev/null +++ b/src/main/kotlin/data/ShoesRepositoryImpl.kt @@ -0,0 +1,19 @@ +package org.example.data + +import org.example.data.model.ShoesDTO + +class ShoesRepositoryImpl: ShoesRepository { + val shoesSource = mutableListOf(shoesList) + + override fun addShoes(vararg shoes: ShoesDTO): { + TODO("Not yet implemented") + } + + override fun getAllShoes() { + TODO("Not yet implemented") + } + + override fun removeShoes() { + TODO("Not yet implemented") + } +} \ No newline at end of file diff --git a/src/main/kotlin/data/localDataSource.kt b/src/main/kotlin/data/localDataSource.kt index d2f8a7b..e74e1d4 100644 --- a/src/main/kotlin/data/localDataSource.kt +++ b/src/main/kotlin/data/localDataSource.kt @@ -1,7 +1,18 @@ package org.example.data +import org.example.data.model.ShoesDTO import org.example.data.model.UserDTO +val shoesList = listOf( + ShoesDTO( + shoesId = 1, + shoesName = "1", + shoesDescription = "123", + shoesUrl = "3", + category = "123" + ) +) + val userList = listOf( UserDTO( userId = 1, diff --git a/src/main/kotlin/data/model/ShoesDTO.kt b/src/main/kotlin/data/model/ShoesDTO.kt new file mode 100644 index 0000000..bd5adf6 --- /dev/null +++ b/src/main/kotlin/data/model/ShoesDTO.kt @@ -0,0 +1,9 @@ +package org.example.data.model + +data class ShoesDTO ( + val shoesId: Int, + val shoesName: String, + val shoesDescription: String, + val shoesUrl: String, + val category: String, +) \ No newline at end of file diff --git a/src/main/kotlin/ui/MainMenuUI.kt b/src/main/kotlin/ui/MainMenuUI.kt new file mode 100644 index 0000000..3f927ce --- /dev/null +++ b/src/main/kotlin/ui/MainMenuUI.kt @@ -0,0 +1,72 @@ +package org.example.ui + +class MainMenuUI( + private val userUI: UserUI +){ + val menuItems = listOf( + "1. Авторизоваться", + "2. Зарегестрироваться", + "3. Exit" + + ) + val menuAuthorizedItems = listOf( + "1. Change password", + "2. Edit profile", + "3. Exit" + + ) + private fun displayMenuItem(menuItem: () -> Unit){ + try { + menuItem() + } + catch (e: Exception){ + println(e.message) + userUI.userAuthorized?.let { + displayMenuForAuthorizeUser() + } + } + } + + fun displayStartMenu(){ + print(menuItems.joinToString("\n")) + val menuPosition = readlnOrNull()?.toIntOrNull() + if(menuPosition == null) displayStartMenu() + when(menuPosition){ + 1 -> { + displayMenuItem { + userUI.authorize() + displayMenuForAuthorizeUser() + } + } + 2 -> { + userUI.registration() + } + 3 ->{ + return + } + else -> { + displayStartMenu() + } + } + } + + private fun displayMenuForAuthorizeUser(){ + print(menuAuthorizedItems.joinToString("\n")) + val menuPosition = readlnOrNull()?.toIntOrNull() + if(menuPosition == null) displayMenuForAuthorizeUser() + when(menuPosition){ + 1 -> { + displayMenuItem { + userUI.changePassword() + } + } + 2 -> { + userUI.edit() + } + 3 -> { + return + } + else -> displayMenuForAuthorizeUser() + } + } +} diff --git a/src/main/kotlin/ui/UserUI.kt b/src/main/kotlin/ui/UserUI.kt index c3c5ce1..d495ba5 100644 --- a/src/main/kotlin/ui/UserUI.kt +++ b/src/main/kotlin/ui/UserUI.kt @@ -26,6 +26,11 @@ class UserUI(private val userUseCase: UserUseCase) { userAuthorized = user println(userResponseToString(user)) } + + fun edit(){ + + } + fun changePassword(){ checkNotNull(userAuthorized){ "Вы не авторизованы"