refactor(input): refactior InputHandler
This commit is contained in:
46
app/src/main/kotlin/lab5/command/InputHandler.kt
Normal file
46
app/src/main/kotlin/lab5/command/InputHandler.kt
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user