Compare commits
No commits in common. "ae881122d018a2f2a90a2ff171285bcebdc1e729" and "6f87c3d25bc8177795fb51b273af6441fb8ef4fc" have entirely different histories.
ae881122d0
...
6f87c3d25b
@ -1,33 +1,26 @@
|
|||||||
package org.example
|
package org.example
|
||||||
|
|
||||||
import org.example.data.repository.ShoesRepositoryImpl
|
import org.example.data.UserRepository
|
||||||
import org.example.data.repository.UserRepositoryImpl
|
import org.example.data.UserRepositoryImpl
|
||||||
import org.example.domain.useCases.ShoesUseCaseImpl
|
import org.example.domain.UserUseCaseImpl
|
||||||
import org.example.domain.useCases.UserUseCaseImpl
|
|
||||||
import org.example.ui.ShoesUI
|
|
||||||
import org.example.ui.UserUI
|
import org.example.ui.UserUI
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val userRepository = UserRepositoryImpl()
|
val userRepository = UserRepositoryImpl()
|
||||||
val shoesRepository = ShoesRepositoryImpl()
|
|
||||||
val userUseCase = UserUseCaseImpl(userRepository)
|
val userUseCase = UserUseCaseImpl(userRepository)
|
||||||
val shoesUseCase = ShoesUseCaseImpl(shoesRepository)
|
|
||||||
val userUI = UserUI(userUseCase)
|
val userUI = UserUI(userUseCase)
|
||||||
val shoesUI = ShoesUI(shoesUseCase)
|
|
||||||
while(true){
|
while(true){
|
||||||
println("Выберите действие:")
|
println("Выберите действие:")
|
||||||
println("1 - Регистрация")
|
println("1 - Регистрация")
|
||||||
println("2 - Авторизация")
|
println("2 - Авторизация")
|
||||||
println("3 - Изменить профиль")
|
println("3 - Изменить профиль")
|
||||||
println("4 - Изменить пароль")
|
println("4 - Изменить пароль")
|
||||||
println("5 - Перейти в каталог")
|
|
||||||
val c = readln()
|
val c = readln()
|
||||||
when(c){
|
when(c){
|
||||||
"1"->userUI.registration()
|
"1"->userUI.registration()
|
||||||
"2"->userUI.authorize()
|
"2"->userUI.authorize()
|
||||||
"3"->userUI.changeProfile()
|
"3"->userUI.changeProfile()
|
||||||
"4"->userUI.changePassword()
|
"4"->userUI.changePassword()
|
||||||
"5"->shoesUI.mainShoes()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package org.example.data.repository
|
package org.example.data
|
||||||
|
|
||||||
import org.example.data.model.UserDTO
|
import org.example.data.model.UserDTO
|
||||||
import org.example.domain.request.RegistrationRequest
|
import org.example.domain.request.RegistrationRequest
|
@ -1,7 +1,6 @@
|
|||||||
package org.example.data.repository
|
package org.example.data
|
||||||
|
|
||||||
import org.example.data.model.UserDTO
|
import org.example.data.model.UserDTO
|
||||||
import org.example.data.userList
|
|
||||||
import org.example.domain.request.RegistrationRequest
|
import org.example.domain.request.RegistrationRequest
|
||||||
|
|
||||||
class UserRepositoryImpl: UserRepository {
|
class UserRepositoryImpl: UserRepository {
|
@ -1,6 +1,5 @@
|
|||||||
package org.example.data
|
package org.example.data
|
||||||
|
|
||||||
import org.example.data.model.ShoesDTO
|
|
||||||
import org.example.data.model.UserDTO
|
import org.example.data.model.UserDTO
|
||||||
|
|
||||||
val userList = listOf(
|
val userList = listOf(
|
||||||
@ -22,39 +21,4 @@ val userList = listOf(
|
|||||||
password = "423",
|
password = "423",
|
||||||
email = "test3@mail.ru",
|
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
|
|
||||||
)
|
|
||||||
)
|
)
|
@ -3,5 +3,5 @@ package org.example.data.model
|
|||||||
data class BasketDTO (
|
data class BasketDTO (
|
||||||
val userId: Int,
|
val userId: Int,
|
||||||
val shoesId: Int,
|
val shoesId: Int,
|
||||||
val countItems: Int,
|
var count_items: Int,
|
||||||
)
|
)
|
@ -1,6 +1,6 @@
|
|||||||
package org.example.data.model
|
package org.example.data.model
|
||||||
|
|
||||||
data class CategoryDTO(
|
data class CategoryDTO(
|
||||||
val categoryId: Int,
|
val category_id: Int,
|
||||||
var categoryName: String
|
var category_name: String
|
||||||
)
|
)
|
@ -1,7 +1,7 @@
|
|||||||
package org.example.data.model
|
package org.example.data.model
|
||||||
|
|
||||||
data class DiscountDTO (
|
data class DiscountDTO (
|
||||||
val discountId: Int,
|
val discount_id: Int,
|
||||||
var discountName: String,
|
var discount_name: String,
|
||||||
var discountPhoto: String
|
var discount_photo: String
|
||||||
)
|
)
|
@ -3,9 +3,9 @@ package org.example.data.model
|
|||||||
import java.sql.Timestamp
|
import java.sql.Timestamp
|
||||||
|
|
||||||
data class OrderDTO (
|
data class OrderDTO (
|
||||||
val orderId: Int,
|
val order_id: Int,
|
||||||
var orderSum: Double,
|
var order_sum: Double,
|
||||||
var deliveryCost: Double,
|
var delivery_cost: Double,
|
||||||
var orderDate: Timestamp
|
var order_date: Timestamp
|
||||||
|
|
||||||
)
|
)
|
@ -1,6 +1,7 @@
|
|||||||
package org.example.data.model
|
package org.example.data.model
|
||||||
|
|
||||||
data class OrderItemDTO (
|
data class OrderItemDTO (
|
||||||
val orderId: Int,
|
val order_id: Int,
|
||||||
val shoesId: Int,
|
val shoes_id: Int,
|
||||||
|
|
||||||
)
|
)
|
@ -1,10 +0,0 @@
|
|||||||
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
|
|
||||||
)
|
|
@ -9,5 +9,6 @@ data class SneakersDTO(
|
|||||||
var count: Int,
|
var count: Int,
|
||||||
var photo: String,
|
var photo: String,
|
||||||
var description: Text
|
var description: Text
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
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<ShoesDTO>
|
|
||||||
fun update(id: Int, updateShoes: ShoesDTO): Boolean
|
|
||||||
fun delete(id: Int): Boolean
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
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<ShoesDTO> = 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<ShoesDTO> {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.example.domain.useCases
|
package org.example.domain
|
||||||
|
|
||||||
import org.example.domain.request.AuthorizeRequest
|
import org.example.domain.request.AuthorizeRequest
|
||||||
import org.example.domain.request.ChangePasswordRequest
|
import org.example.domain.request.ChangePasswordRequest
|
@ -1,7 +1,6 @@
|
|||||||
package org.example.domain.useCases
|
package org.example.domain
|
||||||
|
|
||||||
import org.example.data.repository.UserRepository
|
import org.example.data.UserRepository
|
||||||
import org.example.domain.userDtoToUserResponse
|
|
||||||
import org.example.domain.request.AuthorizeRequest
|
import org.example.domain.request.AuthorizeRequest
|
||||||
import org.example.domain.request.ChangePasswordRequest
|
import org.example.domain.request.ChangePasswordRequest
|
||||||
import org.example.domain.request.ChangeProfileRequest
|
import org.example.domain.request.ChangeProfileRequest
|
||||||
@ -20,7 +19,7 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
|
|||||||
require(findUser.password == authorizeRequest.password){
|
require(findUser.password == authorizeRequest.password){
|
||||||
"Пароли не совпадают"
|
"Пароли не совпадают"
|
||||||
}
|
}
|
||||||
return userDtoToUserResponse(findUser)
|
return UserDtoToUserResponse(findUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun registration(registrationRequest: RegistrationRequest): UserResponse {
|
override fun registration(registrationRequest: RegistrationRequest): UserResponse {
|
||||||
@ -32,7 +31,7 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
|
|||||||
"Такая почта уже существует"
|
"Такая почта уже существует"
|
||||||
}
|
}
|
||||||
val newUser = userRepository.addUser(registrationRequest)
|
val newUser = userRepository.addUser(registrationRequest)
|
||||||
return userDtoToUserResponse(newUser)
|
return UserDtoToUserResponse(newUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun changePassword(changePasswordRequest: ChangePasswordRequest) {
|
override fun changePassword(changePasswordRequest: ChangePasswordRequest) {
|
||||||
@ -46,14 +45,20 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
|
|||||||
|
|
||||||
override fun changeProfile(changeProfileRequest: ChangeProfileRequest): UserResponse {
|
override fun changeProfile(changeProfileRequest: ChangeProfileRequest): UserResponse {
|
||||||
val userProfile = userRepository.findUserById(changeProfileRequest.userId)
|
val userProfile = userRepository.findUserById(changeProfileRequest.userId)
|
||||||
|
checkNotNull(userProfile){"Пользователь не найден"}
|
||||||
userProfile.apply {
|
userProfile.apply {
|
||||||
phone = changeProfileRequest.phone
|
phone = changeProfileRequest.phone
|
||||||
address = changeProfileRequest.address
|
address = changeProfileRequest.address
|
||||||
lastName = changeProfileRequest.lastname
|
lastName = changeProfileRequest.lastname
|
||||||
email = changeProfileRequest.email
|
email = changeProfileRequest.email
|
||||||
}
|
}
|
||||||
|
|
||||||
userRepository.updateUserById(changeProfileRequest.userId,userProfile)
|
userRepository.updateUserById(changeProfileRequest.userId,userProfile)
|
||||||
return userDtoToUserResponse(userProfile)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return UserDtoToUserResponse(userProfile)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ package org.example.domain
|
|||||||
import org.example.data.model.UserDTO
|
import org.example.data.model.UserDTO
|
||||||
import org.example.domain.response.UserResponse
|
import org.example.domain.response.UserResponse
|
||||||
|
|
||||||
fun userDtoToUserResponse(userDTO: UserDTO) = UserResponse(
|
fun UserDtoToUserResponse(userDTO: UserDTO) = UserResponse(
|
||||||
lastName = userDTO.lastName,
|
lastName = userDTO.lastName,
|
||||||
firstName = userDTO.firstName,
|
firstName = userDTO.firstName,
|
||||||
email = userDTO.email,
|
email = userDTO.email,
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
package org.example.domain.request
|
|
||||||
|
|
||||||
data class AddShoesRequest(
|
|
||||||
val name:String,
|
|
||||||
val brand: String,
|
|
||||||
val size: Double,
|
|
||||||
val color: String,
|
|
||||||
val price: Double
|
|
||||||
)
|
|
@ -1,5 +0,0 @@
|
|||||||
package org.example.domain.response
|
|
||||||
|
|
||||||
data class ShoesResponse(
|
|
||||||
val result: Boolean
|
|
||||||
)
|
|
@ -1,13 +0,0 @@
|
|||||||
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<ShoesDTO>
|
|
||||||
fun getShoesById(id: Int):ShoesDTO?
|
|
||||||
fun updateShoes(id: Int, updateShoes: ShoesDTO): ShoesResponse
|
|
||||||
fun delete(id: Int):Boolean
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
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<ShoesDTO> {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,87 +0,0 @@
|
|||||||
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())
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
package org.example.ui
|
package org.example.ui
|
||||||
|
|
||||||
import org.example.domain.useCases.UserUseCase
|
import org.example.domain.UserUseCase
|
||||||
import org.example.domain.request.AuthorizeRequest
|
import org.example.domain.request.AuthorizeRequest
|
||||||
import org.example.domain.request.ChangePasswordRequest
|
import org.example.domain.request.ChangePasswordRequest
|
||||||
import org.example.domain.request.ChangeProfileRequest
|
import org.example.domain.request.ChangeProfileRequest
|
||||||
@ -8,7 +8,7 @@ import org.example.domain.request.RegistrationRequest
|
|||||||
import org.example.domain.response.UserResponse
|
import org.example.domain.response.UserResponse
|
||||||
|
|
||||||
class UserUI(private val userUseCase: UserUseCase) {
|
class UserUI(private val userUseCase: UserUseCase) {
|
||||||
private var userAuthorized: UserResponse? = null
|
var userAuthorized: UserResponse? = null
|
||||||
fun authorize(){
|
fun authorize(){
|
||||||
println("Введите почту")
|
println("Введите почту")
|
||||||
val email = readlnOrNull()
|
val email = readlnOrNull()
|
||||||
|
Loading…
Reference in New Issue
Block a user