This commit is contained in:
localuser 2025-02-03 16:02:46 +03:00
parent 6f87c3d25b
commit fa7ac61510
22 changed files with 289 additions and 34 deletions

View File

@ -1,26 +1,33 @@
package org.example package org.example
import org.example.data.UserRepository import org.example.data.repository.ShoesRepositoryImpl
import org.example.data.UserRepositoryImpl import org.example.data.repository.UserRepositoryImpl
import org.example.domain.UserUseCaseImpl import org.example.domain.useCases.ShoesUseCaseImpl
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()
} }
} }

View File

@ -1,5 +1,6 @@
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(
@ -21,4 +22,39 @@ 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
)
) )

View File

@ -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,
var count_items: Int, val countItems: Int,
) )

View File

@ -1,6 +1,6 @@
package org.example.data.model package org.example.data.model
data class CategoryDTO( data class CategoryDTO(
val category_id: Int, val categoryId: Int,
var category_name: String var categoryName: String
) )

View File

@ -1,7 +1,7 @@
package org.example.data.model package org.example.data.model
data class DiscountDTO ( data class DiscountDTO (
val discount_id: Int, val discountId: Int,
var discount_name: String, var discountName: String,
var discount_photo: String var discountPhoto: String
) )

View File

@ -3,9 +3,9 @@ package org.example.data.model
import java.sql.Timestamp import java.sql.Timestamp
data class OrderDTO ( data class OrderDTO (
val order_id: Int, val orderId: Int,
var order_sum: Double, var orderSum: Double,
var delivery_cost: Double, var deliveryCost: Double,
var order_date: Timestamp var orderDate: Timestamp
) )

View File

@ -1,7 +1,6 @@
package org.example.data.model package org.example.data.model
data class OrderItemDTO ( data class OrderItemDTO (
val order_id: Int, val orderId: Int,
val shoes_id: Int, val shoesId: Int,
) )

View File

@ -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
)

View File

@ -9,6 +9,5 @@ data class SneakersDTO(
var count: Int, var count: Int,
var photo: String, var photo: String,
var description: Text var description: Text
) )

View File

@ -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<ShoesDTO>
fun update(id: Int, updateShoes: ShoesDTO): Boolean
fun delete(id: Int): Boolean
}

View File

@ -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<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
}
}

View File

@ -1,4 +1,4 @@
package org.example.data package org.example.data.repository
import org.example.data.model.UserDTO import org.example.data.model.UserDTO
import org.example.domain.request.RegistrationRequest import org.example.domain.request.RegistrationRequest

View File

@ -1,6 +1,7 @@
package org.example.data package org.example.data.repository
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 {

View File

@ -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,

View File

@ -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
)

View File

@ -0,0 +1,5 @@
package org.example.domain.response
data class ShoesResponse(
val result: Boolean
)

View File

@ -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<ShoesDTO>
fun getShoesById(id: Int):ShoesDTO?
fun updateShoes(id: Int, updateShoes: ShoesDTO): ShoesResponse
fun delete(id: Int):Boolean
}

View File

@ -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<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
}
}

View File

@ -1,4 +1,4 @@
package org.example.domain package org.example.domain.useCases
import org.example.domain.request.AuthorizeRequest import org.example.domain.request.AuthorizeRequest
import org.example.domain.request.ChangePasswordRequest import org.example.domain.request.ChangePasswordRequest

View File

@ -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.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
@ -19,7 +20,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 {
@ -31,7 +32,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) {
@ -45,20 +46,14 @@ 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)
} }
} }

View File

@ -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())
}
}

View File

@ -1,6 +1,6 @@
package org.example.ui 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.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) {
var userAuthorized: UserResponse? = null private var userAuthorized: UserResponse? = null
fun authorize(){ fun authorize(){
println("Введите почту") println("Введите почту")
val email = readlnOrNull() val email = readlnOrNull()