refactor(input): refactior InputHandler

This commit is contained in:
2026-02-28 15:28:08 +03:00
parent 987c1e2aa9
commit b28ff39a5f

View File

@@ -0,0 +1,46 @@
package lab5.command
import lab5.manager.CollectionManager
import lab5.model.Coordinates
import lab5.model.Organization
import lab5.model.Product
import java.time.ZonedDateTime
import java.util.LinkedList
import kotlin.text.toLong
import kotlin.text.toLongOrNull
class InputHandler {
fun productInput(): Product {
println("введите имя")
val name = readLine() ?: "default"
var price: Long?
do {
println("введите цену:")
var input = readLine()
price = input?.toLongOrNull()
if (price == null || price <= 0) {
println("цена должна быть больше 0")
price = null
}
}
while (price == null)
val newProduct =
Product(
id = 1,
name = name,
// TODO: do this coordinates section
coordinates = Coordinates(10L, 10F),
creationDate = ZonedDateTime.now(),
price = price,
unitOfMeasure = null,
// TODO: do this Organization section
manufacturer = Organization(1L, "test", "testtest", 10L),
)
return newProduct
}
}