Files
Lab8-Prog/server/src/main/kotlin/commands/ShowCommand.kt
T
2026-06-13 14:40:31 +03:00

22 lines
786 B
Kotlin

package commands
import database.Repository
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
import models.HumanBeing
import network.Response
@Serializable
class ShowCommand(@Contextual private val repository: Repository) : Command {
override val name = "show"
override val description = "вывести все элементы коллекции"
override val type = CommandType.SIMPLE
override val args = listOf(CommandArgType.NONE)
override fun execute(args: List<String>, humanBeing: HumanBeing?, userId: String): Response {
val all = repository.getAll()
if (all.isEmpty()) return Response(true, "Коллекция пуста.")
return Response(true, all.joinToString("\n") { it.toString() })
}
}