22 lines
786 B
Kotlin
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() })
|
|
}
|
|
}
|