feat(command): add command manager and command
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
8
app/src/main/kotlin/lab5/command/CommandInterface.kt
Normal file
8
app/src/main/kotlin/lab5/command/CommandInterface.kt
Normal file
@@ -0,0 +1,8 @@
|
||||
package lab5.command
|
||||
|
||||
interface CommandInterface {
|
||||
val name: String
|
||||
val description: String
|
||||
|
||||
fun execute(args: String? = null)
|
||||
}
|
||||
11
app/src/main/kotlin/lab5/command/CommandManager.kt
Normal file
11
app/src/main/kotlin/lab5/command/CommandManager.kt
Normal file
@@ -0,0 +1,11 @@
|
||||
package lab5.command
|
||||
|
||||
import lab5.command.commands.Add
|
||||
|
||||
class CommandManager {
|
||||
fun initCommand(command: String) {
|
||||
when (command) {
|
||||
"add" -> Add().execute()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
12
app/src/main/kotlin/lab5/command/commands/Add.kt
Normal file
12
app/src/main/kotlin/lab5/command/commands/Add.kt
Normal 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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user