diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 17351b4..134bcd7 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,26 +1,33 @@ package org.example -import org.example.data.UserRepository -import org.example.data.UserRepositoryImpl -import org.example.domain.UserUseCaseImpl +import org.example.data.repository.ShoesRepositoryImpl +import org.example.data.repository.UserRepositoryImpl +import org.example.domain.useCases.ShoesUseCaseImpl +import org.example.domain.useCases.UserUseCaseImpl +import org.example.ui.ShoesUI import org.example.ui.UserUI fun main() { val userRepository = UserRepositoryImpl() + val shoesRepository = ShoesRepositoryImpl() val userUseCase = UserUseCaseImpl(userRepository) + val shoesUseCase = ShoesUseCaseImpl(shoesRepository) val userUI = UserUI(userUseCase) + val shoesUI = ShoesUI(shoesUseCase) while(true){ println("Выберите действие:") println("1 - Регистрация") println("2 - Авторизация") println("3 - Изменить профиль") println("4 - Изменить пароль") + println("5 - Перейти в каталог") val c = readln() when(c){ "1"->userUI.registration() "2"->userUI.authorize() "3"->userUI.changeProfile() "4"->userUI.changePassword() + "5"->shoesUI.mainShoes() } } diff --git a/src/main/kotlin/data/localDataSource.kt b/src/main/kotlin/data/localDataSource.kt index d2f8a7b..d89690f 100644 --- a/src/main/kotlin/data/localDataSource.kt +++ b/src/main/kotlin/data/localDataSource.kt @@ -1,5 +1,6 @@ package org.example.data +import org.example.data.model.ShoesDTO import org.example.data.model.UserDTO val userList = listOf( @@ -21,4 +22,39 @@ val userList = listOf( password = "423", email = "test3@mail.ru", ), +) + +val shoes = listOf( + ShoesDTO( + id = 1, + name = "MegaSuperShoes", + size = 40.5, + brand = "Gucci", + color = "Black", + price = 1000.0 + ), + ShoesDTO( + id = 2, + name = "MegaSuperUltraShoes", + size = 41.5, + brand = "Gucci", + color = "Black", + price = 10000.0 + ), + ShoesDTO( + id = 3, + name = "MegaSuperUltraProShoes", + size = 42.5, + brand = "Gucci", + color = "Black", + price = 100000.0 + ), + ShoesDTO( + id = 4, + name = "MegaSuperUltraProMaxShoes", + size = 42.0, + brand = "Gucci", + color = "Black", + price = 1000000.0 + ) ) \ No newline at end of file diff --git a/src/main/kotlin/data/model/BasketDTO.kt b/src/main/kotlin/data/model/BasketDTO.kt index fc8fe53..c50e8b0 100644 --- a/src/main/kotlin/data/model/BasketDTO.kt +++ b/src/main/kotlin/data/model/BasketDTO.kt @@ -3,5 +3,5 @@ package org.example.data.model data class BasketDTO ( val userId: Int, val shoesId: Int, - var count_items: Int, + val countItems: Int, ) \ No newline at end of file diff --git a/src/main/kotlin/data/model/CategoryDTO.kt b/src/main/kotlin/data/model/CategoryDTO.kt index c136b28..9f5882b 100644 --- a/src/main/kotlin/data/model/CategoryDTO.kt +++ b/src/main/kotlin/data/model/CategoryDTO.kt @@ -1,6 +1,6 @@ package org.example.data.model data class CategoryDTO( - val category_id: Int, - var category_name: String + val categoryId: Int, + var categoryName: String ) \ No newline at end of file diff --git a/src/main/kotlin/data/model/DiscountDTO.kt b/src/main/kotlin/data/model/DiscountDTO.kt index f29b69e..f5875f6 100644 --- a/src/main/kotlin/data/model/DiscountDTO.kt +++ b/src/main/kotlin/data/model/DiscountDTO.kt @@ -1,7 +1,7 @@ package org.example.data.model data class DiscountDTO ( - val discount_id: Int, - var discount_name: String, - var discount_photo: String + val discountId: Int, + var discountName: String, + var discountPhoto: String ) \ No newline at end of file diff --git a/src/main/kotlin/data/model/OrderDTO.kt b/src/main/kotlin/data/model/OrderDTO.kt index 6793981..a20bf56 100644 --- a/src/main/kotlin/data/model/OrderDTO.kt +++ b/src/main/kotlin/data/model/OrderDTO.kt @@ -3,9 +3,9 @@ package org.example.data.model import java.sql.Timestamp data class OrderDTO ( - val order_id: Int, - var order_sum: Double, - var delivery_cost: Double, - var order_date: Timestamp + val orderId: Int, + var orderSum: Double, + var deliveryCost: Double, + var orderDate: Timestamp ) \ No newline at end of file diff --git a/src/main/kotlin/data/model/OrderItemDTO.kt b/src/main/kotlin/data/model/OrderItemDTO.kt index b4c589b..1f73777 100644 --- a/src/main/kotlin/data/model/OrderItemDTO.kt +++ b/src/main/kotlin/data/model/OrderItemDTO.kt @@ -1,7 +1,6 @@ package org.example.data.model data class OrderItemDTO ( - val order_id: Int, - val shoes_id: Int, - + val orderId: Int, + val shoesId: Int, ) \ No newline at end of file diff --git a/src/main/kotlin/data/model/ShoesDTO.kt b/src/main/kotlin/data/model/ShoesDTO.kt new file mode 100644 index 0000000..729834c --- /dev/null +++ b/src/main/kotlin/data/model/ShoesDTO.kt @@ -0,0 +1,10 @@ +package org.example.data.model + +data class ShoesDTO( + var id: Int, + var name:String, + var brand: String, + var size: Double, + var color: String, + var price: Double +) diff --git a/src/main/kotlin/data/model/SneakersDTO.kt b/src/main/kotlin/data/model/SneakersDTO.kt index 9bf1393..cf787d8 100644 --- a/src/main/kotlin/data/model/SneakersDTO.kt +++ b/src/main/kotlin/data/model/SneakersDTO.kt @@ -9,6 +9,5 @@ data class SneakersDTO( var count: Int, var photo: String, var description: Text - ) diff --git a/src/main/kotlin/data/repository/ShoesRepository.kt b/src/main/kotlin/data/repository/ShoesRepository.kt new file mode 100644 index 0000000..a5acd22 --- /dev/null +++ b/src/main/kotlin/data/repository/ShoesRepository.kt @@ -0,0 +1,12 @@ +package org.example.data.repository + +import org.example.data.model.ShoesDTO +import org.example.domain.request.AddShoesRequest + +interface ShoesRepository { + fun add(addShoesRequest: AddShoesRequest): ShoesDTO + fun getShoesById(id: Int):ShoesDTO? + fun getAllShoes(): List + fun update(id: Int, updateShoes: ShoesDTO): Boolean + fun delete(id: Int): Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/data/repository/ShoesRepositoryImpl.kt b/src/main/kotlin/data/repository/ShoesRepositoryImpl.kt new file mode 100644 index 0000000..b74ad2e --- /dev/null +++ b/src/main/kotlin/data/repository/ShoesRepositoryImpl.kt @@ -0,0 +1,45 @@ +package org.example.data.repository + +import org.example.data.model.ShoesDTO +import org.example.data.shoes +import org.example.domain.request.AddShoesRequest + +class ShoesRepositoryImpl: ShoesRepository { + private val shoesSource: MutableList = shoes.toMutableList() + override fun add(addShoesRequest: AddShoesRequest): ShoesDTO{ + val newShoes = ShoesDTO( + id = shoesSource.size+1, + name = addShoesRequest.name, + brand = addShoesRequest.brand, + size = addShoesRequest.size, + color = addShoesRequest.color, + price = addShoesRequest.price + ) + shoesSource.add(newShoes) + return newShoes + } + + override fun getShoesById(id: Int): ShoesDTO { + val need = shoesSource.first{it.id==id} + return need + } + + override fun getAllShoes(): List { + return shoesSource + } + + override fun update(id: Int,updateShoes:ShoesDTO): Boolean { + val updatable = shoesSource.first { it.id == id } + updatable.name=updateShoes.name + updatable.brand=updateShoes.brand + updatable.size=updateShoes.size + updatable.color=updateShoes.color + updatable.price=updateShoes.price + return(true) + } + + override fun delete(id: Int): Boolean { + shoesSource.removeIf {it.id==id} + return true + } +} \ No newline at end of file diff --git a/src/main/kotlin/data/UserRepository.kt b/src/main/kotlin/data/repository/UserRepository.kt similarity index 91% rename from src/main/kotlin/data/UserRepository.kt rename to src/main/kotlin/data/repository/UserRepository.kt index dc250ff..2b16803 100644 --- a/src/main/kotlin/data/UserRepository.kt +++ b/src/main/kotlin/data/repository/UserRepository.kt @@ -1,4 +1,4 @@ -package org.example.data +package org.example.data.repository import org.example.data.model.UserDTO import org.example.domain.request.RegistrationRequest diff --git a/src/main/kotlin/data/UserRepositoryImpl.kt b/src/main/kotlin/data/repository/UserRepositoryImpl.kt similarity index 95% rename from src/main/kotlin/data/UserRepositoryImpl.kt rename to src/main/kotlin/data/repository/UserRepositoryImpl.kt index c0b78ec..93eeb74 100644 --- a/src/main/kotlin/data/UserRepositoryImpl.kt +++ b/src/main/kotlin/data/repository/UserRepositoryImpl.kt @@ -1,6 +1,7 @@ -package org.example.data +package org.example.data.repository import org.example.data.model.UserDTO +import org.example.data.userList import org.example.domain.request.RegistrationRequest class UserRepositoryImpl: UserRepository { diff --git a/src/main/kotlin/domain/mapper.kt b/src/main/kotlin/domain/mapper.kt index 6885c6e..64a98ba 100644 --- a/src/main/kotlin/domain/mapper.kt +++ b/src/main/kotlin/domain/mapper.kt @@ -3,7 +3,7 @@ package org.example.domain import org.example.data.model.UserDTO import org.example.domain.response.UserResponse -fun UserDtoToUserResponse(userDTO: UserDTO) = UserResponse( +fun userDtoToUserResponse(userDTO: UserDTO) = UserResponse( lastName = userDTO.lastName, firstName = userDTO.firstName, email = userDTO.email, diff --git a/src/main/kotlin/domain/request/AddShoesRequest.kt b/src/main/kotlin/domain/request/AddShoesRequest.kt new file mode 100644 index 0000000..6e5bc8f --- /dev/null +++ b/src/main/kotlin/domain/request/AddShoesRequest.kt @@ -0,0 +1,9 @@ +package org.example.domain.request + +data class AddShoesRequest( + val name:String, + val brand: String, + val size: Double, + val color: String, + val price: Double +) diff --git a/src/main/kotlin/domain/response/ShoesResponse.kt b/src/main/kotlin/domain/response/ShoesResponse.kt new file mode 100644 index 0000000..cc78e5f --- /dev/null +++ b/src/main/kotlin/domain/response/ShoesResponse.kt @@ -0,0 +1,5 @@ +package org.example.domain.response + +data class ShoesResponse( + val result: Boolean +) diff --git a/src/main/kotlin/domain/useCases/ShoesUseCase.kt b/src/main/kotlin/domain/useCases/ShoesUseCase.kt new file mode 100644 index 0000000..2ef25af --- /dev/null +++ b/src/main/kotlin/domain/useCases/ShoesUseCase.kt @@ -0,0 +1,13 @@ +package org.example.domain.useCases + +import org.example.data.model.ShoesDTO +import org.example.domain.request.AddShoesRequest +import org.example.domain.response.ShoesResponse + +interface ShoesUseCase { + fun addShoes(request: AddShoesRequest): ShoesResponse + fun getAllShoes(): List + fun getShoesById(id: Int):ShoesDTO? + fun updateShoes(id: Int, updateShoes: ShoesDTO): ShoesResponse + fun delete(id: Int):Boolean +} \ No newline at end of file diff --git a/src/main/kotlin/domain/useCases/ShoesUseCaseImpl.kt b/src/main/kotlin/domain/useCases/ShoesUseCaseImpl.kt new file mode 100644 index 0000000..e06b82d --- /dev/null +++ b/src/main/kotlin/domain/useCases/ShoesUseCaseImpl.kt @@ -0,0 +1,37 @@ +package org.example.domain.useCases + +import org.example.data.repository.ShoesRepository + +import org.example.data.model.ShoesDTO +import org.example.domain.request.AddShoesRequest +import org.example.domain.response.ShoesResponse + +class ShoesUseCaseImpl(private val shoesRepository: ShoesRepository): ShoesUseCase{ + override fun addShoes(request: AddShoesRequest): ShoesResponse { + shoesRepository.add(request) + return ShoesResponse(true) + } + + override fun getAllShoes(): List { + val allShoes = shoesRepository.getAllShoes() + return allShoes + } + + override fun getShoesById(id: Int): ShoesDTO? { + val needShoes = shoesRepository.getShoesById(id) + return needShoes + } + + override fun updateShoes(id: Int, updateShoes: ShoesDTO): ShoesResponse { + return if(shoesRepository.update(id,updateShoes)) { + ShoesResponse(result = true) + } else { + ShoesResponse(result = false) + } + } + + override fun delete(id: Int): Boolean { + shoesRepository.delete(id) + return true + } +} \ No newline at end of file diff --git a/src/main/kotlin/domain/UserUseCase.kt b/src/main/kotlin/domain/useCases/UserUseCase.kt similarity index 94% rename from src/main/kotlin/domain/UserUseCase.kt rename to src/main/kotlin/domain/useCases/UserUseCase.kt index 277499e..5bf9ee9 100644 --- a/src/main/kotlin/domain/UserUseCase.kt +++ b/src/main/kotlin/domain/useCases/UserUseCase.kt @@ -1,4 +1,4 @@ -package org.example.domain +package org.example.domain.useCases import org.example.domain.request.AuthorizeRequest import org.example.domain.request.ChangePasswordRequest diff --git a/src/main/kotlin/domain/UserUseCaseImpl.kt b/src/main/kotlin/domain/useCases/UserUseCaseImpl.kt similarity index 87% rename from src/main/kotlin/domain/UserUseCaseImpl.kt rename to src/main/kotlin/domain/useCases/UserUseCaseImpl.kt index e2bf39e..1b209c8 100644 --- a/src/main/kotlin/domain/UserUseCaseImpl.kt +++ b/src/main/kotlin/domain/useCases/UserUseCaseImpl.kt @@ -1,6 +1,7 @@ -package org.example.domain +package org.example.domain.useCases -import org.example.data.UserRepository +import org.example.data.repository.UserRepository +import org.example.domain.userDtoToUserResponse import org.example.domain.request.AuthorizeRequest import org.example.domain.request.ChangePasswordRequest import org.example.domain.request.ChangeProfileRequest @@ -19,7 +20,7 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase { require(findUser.password == authorizeRequest.password){ "Пароли не совпадают" } - return UserDtoToUserResponse(findUser) + return userDtoToUserResponse(findUser) } override fun registration(registrationRequest: RegistrationRequest): UserResponse { @@ -31,7 +32,7 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase { "Такая почта уже существует" } val newUser = userRepository.addUser(registrationRequest) - return UserDtoToUserResponse(newUser) + return userDtoToUserResponse(newUser) } override fun changePassword(changePasswordRequest: ChangePasswordRequest) { @@ -45,20 +46,14 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase { override fun changeProfile(changeProfileRequest: ChangeProfileRequest): UserResponse { val userProfile = userRepository.findUserById(changeProfileRequest.userId) - checkNotNull(userProfile){"Пользователь не найден"} userProfile.apply { phone = changeProfileRequest.phone address = changeProfileRequest.address lastName = changeProfileRequest.lastname email = changeProfileRequest.email } - userRepository.updateUserById(changeProfileRequest.userId,userProfile) - - - - - return UserDtoToUserResponse(userProfile) + return userDtoToUserResponse(userProfile) } } \ No newline at end of file diff --git a/src/main/kotlin/ui/ShoesUI.kt b/src/main/kotlin/ui/ShoesUI.kt new file mode 100644 index 0000000..8eaa5a2 --- /dev/null +++ b/src/main/kotlin/ui/ShoesUI.kt @@ -0,0 +1,87 @@ +package org.example.ui +import org.example.data.model.ShoesDTO +import org.example.domain.useCases.ShoesUseCase +import org.example.domain.request.AddShoesRequest + +class ShoesUI(private val shoesUseCase: ShoesUseCase) { + + fun mainShoes(){ + while(true){ + println("Выберите действие:") + println("1 - Показать всю обувь") + println("2 - Добавить обувь") + println("3 - Найти обувь по id") + println("4 - Обновить обувь по id") + println("5 - Удалить обувь по id") + val c = readln() + when(c){ + "1"->showCatalog() + "2"->addShoes() + "3"->getShoesById() + "4"->updateShoes() + "5"->delete() + } + } + } + private fun addShoes(){ + println("Введите название модели:") + val name = readln() + println("Введите название бренда:") + val brand = readln() + println("Введите размер пары обуви:") + val size = readln() + println("Введите основной цвет обуви:") + val color = readln() + println("Введите цену:") + val price = readln() + val addShoesRequest = AddShoesRequest( + name=name, + brand = brand, + size = size.toDouble(), + color = color, + price = price.toDouble(), + ) + shoesUseCase.addShoes(addShoesRequest) + } + private fun getShoesById(){ + println("Введите id искомой обуви: ") + val id = readln() + println(shoesUseCase.getShoesById(id.toInt())) + } + private fun showCatalog(){ + val allShoes = shoesUseCase.getAllShoes() + allShoes.forEach { + println(it) + } + println() + } + + private fun updateShoes(){ + println("Введите id обуви, которую хотите обновить:") + val id = readln() + println("Введите название модели:") + val name = readln() + println("Введите название бренда:") + val brand = readln() + println("Введите размер пары обуви:") + val size = readln() + println("Введите основной цвет обуви:") + val color = readln() + println("Введите цену:") + val price = readln() + val update = ShoesDTO( + id=id.toInt(), + name = name, + brand = brand, + size = size.toDouble(), + color = color, + price = price.toDouble() + ) + shoesUseCase.updateShoes(id.toInt(), update) + } + private fun delete(){ + println("Введите id обуви которую хотите удалить из каталога:") + val id = readln() + shoesUseCase.delete(id.toInt()) + } +} \ No newline at end of file diff --git a/src/main/kotlin/ui/UserUI.kt b/src/main/kotlin/ui/UserUI.kt index 7807d02..fd2c131 100644 --- a/src/main/kotlin/ui/UserUI.kt +++ b/src/main/kotlin/ui/UserUI.kt @@ -1,6 +1,6 @@ package org.example.ui -import org.example.domain.UserUseCase +import org.example.domain.UseCases.UserUseCase import org.example.domain.request.AuthorizeRequest import org.example.domain.request.ChangePasswordRequest import org.example.domain.request.ChangeProfileRequest @@ -8,7 +8,7 @@ import org.example.domain.request.RegistrationRequest import org.example.domain.response.UserResponse class UserUI(private val userUseCase: UserUseCase) { - var userAuthorized: UserResponse? = null + private var userAuthorized: UserResponse? = null fun authorize(){ println("Введите почту") val email = readlnOrNull()