mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2026-01-02 02:57:26 +01:00
Added possibility ta create more than one monitoring for the same service
This commit is contained in:
@@ -239,7 +239,7 @@ class Book(val userId: UserId, bot: Bot, apiService: ApiService, dataService: Da
|
||||
} catch {
|
||||
case ex: Exception =>
|
||||
error("Unable to create monitoring", ex)
|
||||
bot.sendMessage(userId.source, lang.unableToCreateMonitoring)
|
||||
bot.sendMessage(userId.source, lang.unableToCreateMonitoring(ex.getMessage))
|
||||
}
|
||||
end()
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ object En extends Lang {
|
||||
|
||||
override def monitoringHasBeenCreated: String = "👍 Monitoring has been created! List of active /monitorings"
|
||||
|
||||
override def unableToCreateMonitoring: String = s"👎 Unable to create monitoring. Please create a /bug"
|
||||
override def unableToCreateMonitoring(reason: String): String = s"👎 Unable to create monitoring. Reason: $reason."
|
||||
|
||||
override def chooseTypeOfMonitoring: String = "<b>➡</b> Please choose type of monitoring you want"
|
||||
|
||||
@@ -303,9 +303,9 @@ object En extends Lang {
|
||||
|${capitalizeFirstLetter(clinic)}: ${term.clinic.name}
|
||||
|${capitalizeFirstLetter(city)}: ${monitoring.cityName}""".stripMargin
|
||||
|
||||
override def maximumMonitoringsLimitExceeded: String = "Maximum monitorings per user is 5"
|
||||
override def maximumMonitoringsLimitExceeded: String = "Maximum monitorings per user is 10"
|
||||
|
||||
override def monitoringOfTheSameTypeExists: String = "You already have active monitoring for the same service /monitorings"
|
||||
override def monitoringOfTheSameTypeExists: String = "You already have active monitoring for the same service and doctor /monitorings"
|
||||
|
||||
override def termIsOutdated: String =
|
||||
s"""❗️ Looks like the term is already booked by someone else
|
||||
|
||||
@@ -99,7 +99,7 @@ trait Lang {
|
||||
|
||||
def monitoringHasBeenCreated: String
|
||||
|
||||
def unableToCreateMonitoring: String
|
||||
def unableToCreateMonitoring(reason: String): String
|
||||
|
||||
def chooseTypeOfMonitoring: String
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ object Ua extends Lang {
|
||||
|
||||
override def monitoringHasBeenCreated: String = "👍 Моніторинг був створений! Список активних /monitorings"
|
||||
|
||||
override def unableToCreateMonitoring: String = s"👎 Не вдається створити моніторинг. Будь ласка, створіть /bug"
|
||||
override def unableToCreateMonitoring(reason: String): String = s"👎 Не вдається створити моніторинг. Причина: $reason."
|
||||
|
||||
override def chooseTypeOfMonitoring: String = "<b>➡</b> Будь ласка, виберіть тип моніторингу"
|
||||
|
||||
@@ -302,9 +302,9 @@ object Ua extends Lang {
|
||||
|${capitalizeFirstLetter(clinic)}: ${term.clinic.name}
|
||||
|${capitalizeFirstLetter(city)}: ${monitoring.cityName}""".stripMargin
|
||||
|
||||
override def maximumMonitoringsLimitExceeded: String = "Максимальна кількість моніторінгів 5"
|
||||
override def maximumMonitoringsLimitExceeded: String = "Максимальна кількість моніторінгів 10"
|
||||
|
||||
override def monitoringOfTheSameTypeExists: String = "У вас вже є активний моніторинг на таку ж саму послугу /monitorings"
|
||||
override def monitoringOfTheSameTypeExists: String = "У вас вже є активний моніторинг на таку ж саму послугу i лiкаря /monitorings"
|
||||
|
||||
override def termIsOutdated: String =
|
||||
s"""❗️ Схоже, що термін вже не є доступним
|
||||
|
||||
@@ -123,15 +123,17 @@ class DataRepository(@Autowired em: EntityManager) {
|
||||
.getResultList.asScala
|
||||
}
|
||||
|
||||
def findActiveMonitoring(accountId: Long, cityId: Long, serviceId: Long): Option[Monitoring] = {
|
||||
def findActiveMonitoring(accountId: Long, cityId: Long, serviceId: Long, doctorId: Long): Option[Monitoring] = {
|
||||
em.createQuery(
|
||||
"""select monitoring from Monitoring monitoring where monitoring.active = true
|
||||
| and monitoring.accountId = :accountId
|
||||
| and monitoring.cityId = :cityId
|
||||
| and monitoring.serviceId = :serviceId""".stripMargin, classOf[Monitoring])
|
||||
| and monitoring.serviceId = :serviceId
|
||||
| and monitoring.doctorId = :doctorId""".stripMargin, classOf[Monitoring])
|
||||
.setParameter("accountId", accountId)
|
||||
.setParameter("cityId", cityId)
|
||||
.setParameter("serviceId", serviceId)
|
||||
.setParameter("doctorId", doctorId)
|
||||
.getResultList.asScala.headOption
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ class DataService {
|
||||
dataRepository.getActiveMonitorings(accountId)
|
||||
}
|
||||
|
||||
def findActiveMonitoring(accountId: Long, cityId: Long, serviceId: Long): Option[Monitoring] = {
|
||||
dataRepository.findActiveMonitoring(accountId, cityId, serviceId)
|
||||
def findActiveMonitoring(accountId: Long, cityId: Long, serviceId: Long, doctorId: Long): Option[Monitoring] = {
|
||||
dataRepository.findActiveMonitoring(accountId, cityId, serviceId, doctorId)
|
||||
}
|
||||
|
||||
def getActiveMonitoringsSince(since: ZonedDateTime): Seq[Monitoring] = {
|
||||
|
||||
@@ -204,8 +204,8 @@ class MonitoringService extends Logger {
|
||||
|
||||
def createMonitoring(monitoring: Monitoring): Monitoring = {
|
||||
val userMonitoringsCount = dataService.getActiveMonitoringsCount(monitoring.accountId)
|
||||
require(userMonitoringsCount + 1 <= 5, lang(monitoring.userId).maximumMonitoringsLimitExceeded)
|
||||
val activeMonitoring = dataService.findActiveMonitoring(monitoring.accountId, monitoring.cityId, monitoring.serviceId)
|
||||
require(userMonitoringsCount + 1 <= 10, lang(monitoring.userId).maximumMonitoringsLimitExceeded)
|
||||
val activeMonitoring = dataService.findActiveMonitoring(monitoring.accountId, monitoring.cityId, monitoring.serviceId, monitoring.doctorId)
|
||||
require(activeMonitoring.isEmpty, lang(monitoring.userId).monitoringOfTheSameTypeExists)
|
||||
dataService.saveMonitoring(monitoring)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user