24 lines
957 B
Kotlin
24 lines
957 B
Kotlin
package commands
|
|
|
|
import collection.CollectionManager
|
|
import kotlinx.serialization.Contextual
|
|
import kotlinx.serialization.Serializable
|
|
import models.HumanBeing
|
|
import network.Response
|
|
|
|
@Serializable
|
|
class AddCommand(@Contextual private val manager: CollectionManager) : Command {
|
|
override val name = "add"
|
|
override val description = "добавить новый элемент в коллекцию"
|
|
override val args = listOf(CommandArgType.NONE)
|
|
override val type = CommandType.MODEL
|
|
|
|
override fun execute(args: List<String>, humanBeing: HumanBeing?): Response {
|
|
humanBeing ?: return Response(false, "[Ошибка] Объект HumanBeing не передан.")
|
|
return if (manager.add(humanBeing))
|
|
Response(true, "Элемент добавлен: ${humanBeing.name} [${humanBeing.id}]")
|
|
else
|
|
Response(false, "Элемент уже существует в коллекции.")
|
|
}
|
|
}
|