init commit

This commit is contained in:
End3r 2025-02-03 16:04:25 +03:00
parent eb8cbbba10
commit 3c01d46a65
12 changed files with 326 additions and 6 deletions

View File

@ -1,14 +1,37 @@
package org.example
import org.example.data.ShoesRepositoryImpl
import org.example.data.UserRepository
import org.example.data.UserRepositoryImpl
import org.example.domain.ShoesUseCase
import org.example.domain.ShoesUseCaseImpl
import org.example.domain.UserUseCaseImpl
import org.example.ui.ShoesUI
import org.example.ui.UserUI
fun main() {
val userRepository = UserRepositoryImpl()
val userUseCase = UserUseCaseImpl(userRepository)
val userUI = UserUI(userUseCase)
val shoesRepository = ShoesRepositoryImpl()
val shoesUseCase = ShoesUseCaseImpl(shoesRepository)
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.main()
}
}
}

View File

@ -0,0 +1,12 @@
package org.example.data
import org.example.data.model.ShoesDTO
import org.example.domain.request.AddShoesRequest
interface ShoesRepository {
fun addShoes(addShoesRequest: AddShoesRequest): ShoesDTO
fun removeShoes(productId: Int): Boolean
fun updateShoes(productId: Int, updatedShoes: ShoesDTO): ShoesDTO
fun getAllShoes():List<ShoesDTO>
fun findShoesById(productId: Int): ShoesDTO
}

View File

@ -0,0 +1,50 @@
package org.example.data
import org.example.data.model.ShoesDTO
import org.example.data.model.UserDTO
import org.example.domain.request.AddShoesRequest
class ShoesRepositoryImpl: ShoesRepository {
private val shoes: MutableList<ShoesDTO> = shoesList.toMutableList()
override fun addShoes(addShoesRequest: AddShoesRequest): ShoesDTO {
val newShoes = ShoesDTO(
productId = shoes.size + 1,
productName = addShoesRequest.productName,
cost = addShoesRequest.cost,
count = addShoesRequest.count,
photo = addShoesRequest.photo,
description = addShoesRequest.description.toString()
)
shoes.add(newShoes)
return newShoes
}
override fun removeShoes(productId:Int): Boolean {
return shoes.removeIf{it.productId == productId }
}
override fun updateShoes(productId: Int,updatedShoes: ShoesDTO): ShoesDTO {
val oldShoes = shoes.firstOrNull{it.productId == productId}
checkNotNull(oldShoes)
oldShoes.productName = updatedShoes.productName
oldShoes.cost = updatedShoes.cost
oldShoes.count = updatedShoes.count
oldShoes.photo = updatedShoes.photo
oldShoes.description = updatedShoes.description
return oldShoes
}
override fun getAllShoes(): List<ShoesDTO> = shoes
override fun findShoesById(productId: Int): ShoesDTO {
val findShoes = shoes.firstOrNull{it.productId == productId}
checkNotNull(findShoes)
return findShoes
}
}

View File

@ -1,5 +1,6 @@
package org.example.data
import org.example.data.model.ShoesDTO
import org.example.data.model.UserDTO
val userList = listOf(
@ -20,5 +21,24 @@ val userList = listOf(
firstName = "Oleg",
password = "423",
email = "test3@mail.ru",
),
)
)
val shoesList = listOf(
ShoesDTO(
productId = 1,
productName = "nikepro",
cost = "100",
count = 15,
photo = "dsds",
description = "Самые топовые кроссы"
),
ShoesDTO(
productId = 2,
productName = "adik",
cost = "2000",
count = 10,
photo = "dsddwsda",
description = "Для четких пацанов"
),
)

View File

@ -1,14 +1,12 @@
package org.example.data.model
import org.w3c.dom.Text
data class SneakersDTO(
data class ShoesDTO(
val productId: Int,
var productName: String,
var cost: String,
var count: Int,
var photo: String,
var description: Text
var description: String
)

View File

@ -0,0 +1,19 @@
package org.example.domain
import org.example.data.model.ShoesDTO
import org.example.domain.request.AddShoesRequest
interface ShoesUseCase {
fun addProductToBasket()
fun addProductToFavorite()
fun addShoes(addShoesRequest: AddShoesRequest): ShoesDTO
fun removeShoes(productId: Int): Boolean
fun updateShoes(productId: Int, updatedShoes: ShoesDTO): ShoesDTO
fun getAllShoes():List<ShoesDTO>
fun findShoesById(productId: Int): ShoesDTO
}

View File

@ -0,0 +1,60 @@
package org.example.domain
import org.example.data.ShoesRepository
import org.example.data.model.ShoesDTO
import org.example.data.shoesList
import org.example.domain.request.AddShoesRequest
class ShoesUseCaseImpl(private val shoesRepository: ShoesRepository): ShoesUseCase {
private val shoes: MutableList<ShoesDTO> = shoesList.toMutableList()
override fun addProductToBasket() {
TODO("Not yet implemented")
}
override fun addProductToFavorite() {
TODO("Not yet implemented")
}
override fun addShoes(addShoesRequest: AddShoesRequest): ShoesDTO {
val newShoes = ShoesDTO(
productId = shoes.size + 1,
productName = addShoesRequest.productName,
cost = addShoesRequest.cost,
count = addShoesRequest.count,
photo = addShoesRequest.photo,
description = addShoesRequest.description.toString()
)
shoes.add(newShoes)
return newShoes
}
override fun removeShoes(productId:Int): Boolean {
return shoes.removeIf{it.productId == productId }
}
override fun updateShoes(productId: Int,updatedShoes: ShoesDTO): ShoesDTO {
val oldShoes = shoes.firstOrNull{it.productId == productId}
checkNotNull(oldShoes)
oldShoes.productName = updatedShoes.productName
oldShoes.cost = updatedShoes.cost
oldShoes.count = updatedShoes.count
oldShoes.photo = updatedShoes.photo
oldShoes.description = updatedShoes.description
return oldShoes
}
override fun getAllShoes(): List<ShoesDTO> = shoes
override fun findShoesById(productId: Int): ShoesDTO {
val findShoes = shoes.firstOrNull{it.productId == productId}
checkNotNull(findShoes)
return findShoes
}
}

View File

@ -57,7 +57,6 @@ class UserUseCaseImpl(private val userRepository: UserRepository): UserUseCase {
return UserDtoToUserResponse(userProfile)
}

View File

@ -1,6 +1,8 @@
package org.example.domain
import org.example.data.model.ShoesDTO
import org.example.data.model.UserDTO
import org.example.domain.response.ShoesResponse
import org.example.domain.response.UserResponse
fun UserDtoToUserResponse(userDTO: UserDTO) = UserResponse(
@ -10,4 +12,13 @@ fun UserDtoToUserResponse(userDTO: UserDTO) = UserResponse(
phone = userDTO.phone,
userId = userDTO.userId,
address = userDTO.address,
)
fun ShoesDTOToShoesResponse(shoesDTO: ShoesDTO) = ShoesResponse(
productName = shoesDTO.productName,
cost = shoesDTO.cost,
count = shoesDTO.count,
photo = shoesDTO.photo,
description = shoesDTO.description,
productId = shoesDTO.productId
)

View File

@ -0,0 +1,9 @@
package org.example.domain.request
data class AddShoesRequest(
var productName: String,
var cost: String,
var count: Int,
var photo: String,
var description: String
)

View File

@ -0,0 +1,10 @@
package org.example.domain.response
data class ShoesResponse (
val productId: Int,
var productName: String,
var cost: String,
var count: Int,
var photo: String,
var description: String
)

View File

@ -0,0 +1,109 @@
package org.example.ui
import org.example.data.model.ShoesDTO
import org.example.domain.ShoesUseCase
import org.example.domain.request.AddShoesRequest
class ShoesUI(private val shoesUseCase: ShoesUseCase) {
fun main(){
while (true){
println("Выберите действие:")
println("1 - Показать все товары")
println("2 - Удалить товар")
println("3 - Найти товар")
println("4 - Обновить товар")
println("5 - Добавить")
println("6 - Вернуться назад (пока не рабоатает)")
val c = readln()
when(c){
"1"-> getAllShoes()
"2"-> removeShoesById()
"3"-> findShoesById()
"4"-> updateShoes()
"5"-> addShoes()
}
}
}
fun addShoes(){
println("Введите название товара")
var productName = readln()
checkNotNull(productName){"Имя не должно быть пустым"}
println("Введите стоимость")
var cost = readln()
checkNotNull(cost){"Стоимость должна быть указана"}
println("Введите количество товара")
var count = readln()
checkNotNull(count){"Количество должно быть указано"}
println("Введите ссылку на фото")
var photo = readln()
checkNotNull(photo){"Ссылка на фото должна быть"}
println("Введите описание товара")
var description = readln()
checkNotNull(description){"Описание товара не должно быть пустым"}
val addShoesRequest = AddShoesRequest(
productName = productName,
cost = cost,
count = count.toInt(),
photo = photo,
description = description
)
val newShoes = shoesUseCase.addShoes(addShoesRequest)
}
fun removeShoesById(){
println("Введите id продукта, который хотите удалить")
var productId = readln().toInt()
checkNotNull(productId){"ID не должно быть пустым"}
var removeShoes = shoesUseCase.removeShoes(productId)
}
fun updateShoes(){
println("Введите id товара, который хотите обноновить ")
val productId = readln().toInt()
checkNotNull(productId){"ID не должно быть пустым"}
println("Введите название товара")
var productName = readln()
checkNotNull(productName){"Имя не должно быть пустым"}
println("Введите стоимость")
var cost = readln()
checkNotNull(cost){"Стоимость должна быть указана"}
println("Введите количество товара")
var count = readln()
checkNotNull(count){"Количество должно быть указано"}
println("Введите ссылку на фото")
var photo = readln()
checkNotNull(photo){"Ссылка на фото должна быть"}
println("Введите описание товара")
var description = readln()
checkNotNull(description){"Описание товара не должно быть пустым"}
val newProduct = ShoesDTO(
productName = productName,
cost = cost,
count = count.toInt(),
photo = photo,
description = description,
productId = productId
)
shoesUseCase.updateShoes(productId,newProduct)
}
fun findShoesById(){
println("Введите id продукта, который хотите найти")
var productId = readln().toInt()
checkNotNull(productId){"ID не должно быть пустым"}
println(shoesUseCase.findShoesById(productId))
}
fun getAllShoes(){
val allShoes = shoesUseCase.getAllShoes()
allShoes.forEach{
println(it)
}
println()
}
}