feat(command): add io in ProductReader

This commit is contained in:
2026-03-01 03:13:46 +03:00
parent 406378c7ad
commit 620958cc66
2 changed files with 10 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
package command package command
import io.IOHandler
import manager.CollectionManager import manager.CollectionManager
import model.Coordinates import model.Coordinates
import model.Organization import model.Organization
@@ -9,21 +10,23 @@ import java.util.LinkedList
import kotlin.text.toLong import kotlin.text.toLong
import kotlin.text.toLongOrNull import kotlin.text.toLongOrNull
class InputHandler { class ProductReader(
private val io: IOHandler,
) {
fun read(): Product { fun read(): Product {
println("введите имя") io.println("введите имя")
val name = readLine() ?: "default" val name = io.readLine() ?: "default"
var price: Long? var price: Long?
do { do {
println("введите цену:") io.println("введите цену:")
var input = readLine() var input = io.readLine()
price = input?.toLongOrNull() price = input?.toLongOrNull()
if (price == null || price <= 0) { if (price == null || price <= 0) {
println("цена должна быть больше 0") io.println("цена должна быть больше 0")
price = null price = null
} }
} }

View File

@@ -12,6 +12,6 @@ class Add(
override fun execute(args: String?) { override fun execute(args: String?) {
io.println("добавляем продукт") io.println("добавляем продукт")
ProductReader().read() ProductReader(io).read()
} }
} }