From 494bf71e612283f8ef6f794084f8e332a9cb6aba Mon Sep 17 00:00:00 2001 From: Pavel Kachalouski Date: Wed, 6 Nov 2019 22:10:30 +0100 Subject: [PATCH] Fix info about parcel with empty states --- src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala b/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala index cbf81e8..e6e7d12 100644 --- a/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala +++ b/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala @@ -74,11 +74,12 @@ object CzechPostDeliveryCheck { } def latestStatePrint(parcelId: String): String = { - val state = latestState - s"$parcelId ($comment) - ${printDateFormat.format(czechPostDateFormat.parse(state.date))} - ${state.text}" + latestState + .map(state => s"$parcelId ($comment) - ${printDateFormat.format(czechPostDateFormat.parse(state.date))} - ${state.text}") + .getOrElse(s"$parcelId ($comment) - NO INFO") } - private def latestState: Entities.State = states.toSeq.maxBy(state => czechPostDateFormat.parse(state.date)) + private def latestState: Option[Entities.State] = states.toSeq.maxByOption(state => czechPostDateFormat.parse(state.date)) } case class State(parcelStates: Map[String, Parcel] = Map.empty) {