feat(command): add command manager and command

This commit is contained in:
2026-02-28 15:29:32 +03:00
parent b28ff39a5f
commit e2f27d0cd2
5 changed files with 38 additions and 53 deletions

View File

@@ -1,9 +1,13 @@
package lab5
import lab5.command.InputManager
import lab5.command.CommandManager
fun main() {
val input = InputManager()
val commandManager = CommandManager()
input.productInput()
while (true) {
val input = readlnOrNull().toString()
commandManager.initCommand(input)
}
}

View File

@@ -0,0 +1,8 @@
package lab5.command
interface CommandInterface {
val name: String
val description: String
fun execute(args: String? = null)
}

View File

@@ -0,0 +1,11 @@
package lab5.command
import lab5.command.commands.Add
class CommandManager {
fun initCommand(command: String) {
when (command) {
"add" -> Add().execute()
}
}
}

View File

@@ -1,50 +0,0 @@
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 InputManager {
fun productInput() {
val manager = CollectionManager()
println("введите имя")
val name = readLine() ?: "default"
var price: Long?
do {
println("введите цену:")
var input = readLine()
price = input?.toLongOrNull()
if (price == null) {
println("цена должна быть числом")
} else if (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),
)
manager.addProduct(newProduct)
}
}

View File

@@ -0,0 +1,12 @@
package lab5.command.commands
import lab5.command.CommandInterface
class Add : CommandInterface {
override val name = "add"
override val description = "add product"
override fun execute(args: String?) {
println("fdada")
}
}