mirror of
https://github.com/dyrkin/luxmed-bot.git
synced 2025-12-27 23:46:38 +01:00
remove "submit bug" support
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
databaseChangeLog:
|
||||
- changeSet:
|
||||
id: 05
|
||||
author: dyrkin
|
||||
preConditions:
|
||||
onFail: MARK_RAN
|
||||
tableExists:
|
||||
tableName: bug
|
||||
changes:
|
||||
- dropTable:
|
||||
tableName: bug
|
||||
@@ -13,4 +13,7 @@ databaseChangeLog:
|
||||
relativeToChangelogFile: true
|
||||
- include:
|
||||
file: changelog/04-add-payerid-column-to-monitoring.yml
|
||||
relativeToChangelogFile: true
|
||||
- include:
|
||||
file: changelog/05-drop-bugs-table.yml
|
||||
relativeToChangelogFile: true
|
||||
@@ -7,16 +7,12 @@ import com.lbs.bot.Bot
|
||||
import com.lbs.bot.telegram.TelegramBot
|
||||
import com.lbs.server.conversation._
|
||||
import com.lbs.server.lang.Localization
|
||||
import com.lbs.server.repository.model
|
||||
import com.lbs.server.repository.model.Monitoring
|
||||
import com.lbs.server.service.{ApiService, DataService, MonitoringService}
|
||||
import org.jasypt.util.text.{StrongTextEncryptor, TextEncryptor}
|
||||
import org.springframework.beans.factory.annotation.{Autowired, Value}
|
||||
import org.springframework.context.annotation.{Bean, Configuration}
|
||||
|
||||
import scala.io.Source
|
||||
import scala.util.Try
|
||||
|
||||
@Configuration
|
||||
class BootConfig {
|
||||
@Value("${security.secret}")
|
||||
@@ -85,10 +81,6 @@ class BootConfig {
|
||||
def visitsFactory: UserIdTo[Visits] =
|
||||
userId => new Visits(userId, bot, apiService, localization, visitsPagerFactory)(actorSystem)
|
||||
|
||||
@Bean
|
||||
def bugFactory: UserIdTo[Bug] =
|
||||
userId => new Bug(userId, bot, dataService, bugPagerFactory, localization)(actorSystem)
|
||||
|
||||
@Bean
|
||||
def settingsFactory: UserIdTo[Settings] =
|
||||
userId => new Settings(userId, bot, dataService, localization)(actorSystem)
|
||||
@@ -100,7 +92,7 @@ class BootConfig {
|
||||
@Bean
|
||||
def chatFactory: UserIdTo[Chat] =
|
||||
userId => new Chat(userId, dataService, monitoringService, bookFactory, helpFactory,
|
||||
monitoringsFactory, monitoringsHistoryFactory, historyFactory, visitsFactory, settingsFactory, bugFactory, accountFactory)(actorSystem)
|
||||
monitoringsFactory, monitoringsHistoryFactory, historyFactory, visitsFactory, settingsFactory, accountFactory)(actorSystem)
|
||||
|
||||
@Bean
|
||||
def datePickerFactory: UserIdWithOriginatorTo[DatePicker] = (userId, originator) =>
|
||||
@@ -129,13 +121,6 @@ class BootConfig {
|
||||
(page: Int, pages: Int) => lang(userId).upcomingVisitsHeader(page, pages),
|
||||
Some("cancel"), localization, originator)(actorSystem)
|
||||
|
||||
@Bean
|
||||
def bugPagerFactory: UserIdWithOriginatorTo[Pager[model.Bug]] = (userId, originator) =>
|
||||
new Pager[model.Bug](userId, bot,
|
||||
(bug: model.Bug, page: Int, index: Int) => lang(userId).bugEntry(bug, page, index),
|
||||
(page: Int, pages: Int) => lang(userId).bugsHeader(page, pages),
|
||||
None, localization, originator)(actorSystem)
|
||||
|
||||
@Bean
|
||||
def historyPagerFactory: UserIdWithOriginatorTo[Pager[HistoricVisit]] = (userId, originator) =>
|
||||
new Pager[HistoricVisit](userId, bot,
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
|
||||
package com.lbs.server.conversation
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import com.lbs.bot.model.{Button, Command}
|
||||
import com.lbs.bot.{Bot, _}
|
||||
import com.lbs.server.conversation.Bug._
|
||||
import com.lbs.server.conversation.Login.UserId
|
||||
import com.lbs.server.conversation.Pager.SimpleItemsProvider
|
||||
import com.lbs.server.conversation.base.Conversation
|
||||
import com.lbs.server.lang.{Localizable, Localization}
|
||||
import com.lbs.server.repository.model
|
||||
import com.lbs.server.service.DataService
|
||||
import com.lbs.server.util.MessageExtractors
|
||||
|
||||
class Bug(val userId: UserId, bot: Bot, dataService: DataService, bugPagerFactory: UserIdWithOriginatorTo[Pager[model.Bug]],
|
||||
val localization: Localization)(val actorSystem: ActorSystem) extends Conversation[Unit] with Localizable {
|
||||
|
||||
private val bugPager = bugPagerFactory(userId, self)
|
||||
|
||||
entryPoint(askAction)
|
||||
|
||||
def askAction: Step =
|
||||
ask { _ =>
|
||||
bot.sendMessage(userId.source, lang.bugAction, inlineKeyboard =
|
||||
createInlineKeyboard(Seq(Button(lang.createNewBug, Tags.SubmitNew), Button(lang.showSubmittedBugs, Tags.ListSubmitted))))
|
||||
} onReply {
|
||||
case Msg(Command(_, _, Some(Tags.SubmitNew)), _) =>
|
||||
goto(askBugDescription)
|
||||
case Msg(Command(_, _, Some(Tags.ListSubmitted)), _) =>
|
||||
goto(displaySubmittedBugs)
|
||||
}
|
||||
|
||||
def displaySubmittedBugs: Step =
|
||||
process { _ =>
|
||||
val bugs = dataService.getBugs(userId.userId)
|
||||
bugPager.restart()
|
||||
bugPager ! Right[Throwable, Seq[model.Bug]](bugs).map(new SimpleItemsProvider(_))
|
||||
goto(processResponseFromPager)
|
||||
}
|
||||
|
||||
def processResponseFromPager: Step =
|
||||
monologue {
|
||||
case Msg(cmd: Command, _) =>
|
||||
bugPager ! cmd
|
||||
stay()
|
||||
case Msg(Pager.NoItemsFound, _) =>
|
||||
bot.sendMessage(userId.source, lang.noSubmittedIssuesFound)
|
||||
end()
|
||||
}
|
||||
|
||||
def askBugDescription: Step =
|
||||
ask { _ =>
|
||||
bot.sendMessage(userId.source, lang.enterIssueDetails)
|
||||
} onReply {
|
||||
case Msg(MessageExtractors.TextCommand(details), _) =>
|
||||
val bugId = dataService.submitBug(userId.userId, userId.source.sourceSystem.id, details)
|
||||
bot.sendMessage(userId.source, lang.bugHasBeenCreated(bugId.getOrElse(-1L)))
|
||||
end()
|
||||
}
|
||||
|
||||
beforeDestroy {
|
||||
bugPager.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
object Bug {
|
||||
|
||||
object Tags {
|
||||
val SubmitNew = "submit"
|
||||
val ListSubmitted = "list"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,8 +14,7 @@ import scala.util.matching.Regex
|
||||
|
||||
class Chat(val userId: UserId, dataService: DataService, monitoringService: MonitoringService, bookingFactory: UserIdTo[Book],
|
||||
helpFactory: UserIdTo[Help], monitoringsFactory: UserIdTo[Monitorings], monitoringsHistoryFactory: UserIdTo[MonitoringsHistory], historyFactory: UserIdTo[History],
|
||||
visitsFactory: UserIdTo[Visits], settingsFactory: UserIdTo[Settings],
|
||||
bugFactory: UserIdTo[Bug], accountFactory: UserIdTo[Account])(val actorSystem: ActorSystem) extends Conversation[Unit] with Logger {
|
||||
visitsFactory: UserIdTo[Visits], settingsFactory: UserIdTo[Settings], accountFactory: UserIdTo[Account])(val actorSystem: ActorSystem) extends Conversation[Unit] with Logger {
|
||||
|
||||
private val book = bookingFactory(userId)
|
||||
private val help = helpFactory(userId)
|
||||
@@ -24,7 +23,6 @@ class Chat(val userId: UserId, dataService: DataService, monitoringService: Moni
|
||||
private val history = historyFactory(userId)
|
||||
private val visits = visitsFactory(userId)
|
||||
private val settings = settingsFactory(userId)
|
||||
private val bug = bugFactory(userId)
|
||||
private val account = accountFactory(userId)
|
||||
|
||||
entryPoint(helpChat)
|
||||
@@ -60,13 +58,6 @@ class Chat(val userId: UserId, dataService: DataService, monitoringService: Moni
|
||||
stay()
|
||||
}
|
||||
|
||||
private def bugChat: Step =
|
||||
dialogue(bug) {
|
||||
case Msg(TextCommand("/bug"), _) =>
|
||||
bug.restart()
|
||||
stay()
|
||||
}
|
||||
|
||||
private def monitoringsChat: Step =
|
||||
dialogue(monitorings) {
|
||||
case Msg(TextCommand("/monitorings"), _) =>
|
||||
@@ -106,9 +97,6 @@ class Chat(val userId: UserId, dataService: DataService, monitoringService: Moni
|
||||
}
|
||||
|
||||
private def secondaryState(interactional: Interactional): MessageProcessorFn = {
|
||||
case Msg(cmd@TextCommand("/bug"), _) =>
|
||||
this ! cmd
|
||||
goto(bugChat)
|
||||
case Msg(cmd@TextCommand("/help"), _) =>
|
||||
self ! cmd
|
||||
goto(helpChat)
|
||||
@@ -155,7 +143,6 @@ class Chat(val userId: UserId, dataService: DataService, monitoringService: Moni
|
||||
history.destroy()
|
||||
visits.destroy()
|
||||
settings.destroy()
|
||||
bug.destroy()
|
||||
account.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Locale
|
||||
import com.lbs.api.json.model.{AvailableVisitsTermPresentation, HistoricVisit, ReservedVisit, ValuationsResponse}
|
||||
import com.lbs.server.conversation.Book
|
||||
import com.lbs.server.conversation.StaticData.StaticDataConfig
|
||||
import com.lbs.server.repository.model.{Bug, Monitoring}
|
||||
import com.lbs.server.repository.model.Monitoring
|
||||
import com.lbs.server.util.DateTimeUtil._
|
||||
|
||||
object En extends Lang {
|
||||
@@ -182,7 +182,7 @@ object En extends Lang {
|
||||
|/accounts - manage Luxmed accounts
|
||||
|/login - login again
|
||||
|/settings - settings, e.g. lang
|
||||
|/bug - submit an issue""".stripMargin
|
||||
|/help - the help""".stripMargin
|
||||
|
||||
override def dateFromIs(dateFrom: ZonedDateTime): String = s"📅 Date from is ${formatDate(dateFrom, locale)}"
|
||||
|
||||
@@ -222,13 +222,6 @@ object En extends Lang {
|
||||
override def upcomingVisitsHeader(page: Int, pages: Int): String =
|
||||
withPages("<b>➡</b> Reserved visits", page, pages)
|
||||
|
||||
override def bugEntry(bug: Bug, page: Int, index: Int): String =
|
||||
s"""⏱ <b>${formatDateTime(bug.submitted, locale)}</b>
|
||||
|Description: ${bug.details}
|
||||
|State: <b>${if (bug.resolved) "✅ Resolved" else "🚫 Unresolved"}</b>
|
||||
|
|
||||
|""".stripMargin
|
||||
|
||||
override def bugsHeader(page: Int, pages: Int): String =
|
||||
withPages("<b>➡</b> Submitted issues", page, pages)
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.Locale
|
||||
import com.lbs.api.json.model.{AvailableVisitsTermPresentation, HistoricVisit, ReservedVisit, ValuationsResponse}
|
||||
import com.lbs.server.conversation.Book.BookingData
|
||||
import com.lbs.server.conversation.StaticData.StaticDataConfig
|
||||
import com.lbs.server.repository.model
|
||||
import com.lbs.server.repository.model.Monitoring
|
||||
|
||||
import scala.io.Source
|
||||
@@ -169,8 +168,6 @@ trait Lang {
|
||||
|
||||
def upcomingVisitsHeader(page: Int, pages: Int): String
|
||||
|
||||
def bugEntry(bug: model.Bug, page: Int, index: Int): String
|
||||
|
||||
def bugsHeader(page: Int, pages: Int): String
|
||||
|
||||
def monitoringEntry(monitoring: Monitoring, page: Int, index: Int): String
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.Locale
|
||||
import com.lbs.api.json.model.{AvailableVisitsTermPresentation, HistoricVisit, ReservedVisit, ValuationsResponse}
|
||||
import com.lbs.server.conversation.Book
|
||||
import com.lbs.server.conversation.StaticData.StaticDataConfig
|
||||
import com.lbs.server.repository.model.{Bug, Monitoring}
|
||||
import com.lbs.server.repository.model.Monitoring
|
||||
import com.lbs.server.util.DateTimeUtil._
|
||||
|
||||
object Ua extends Lang {
|
||||
@@ -181,7 +181,7 @@ object Ua extends Lang {
|
||||
|/accounts - управління акаунтами Luxmed
|
||||
|/login - залогінитися знову
|
||||
|/settings - налаштування
|
||||
|/bug - відправити баг""".stripMargin
|
||||
|/help - допомога""".stripMargin
|
||||
|
||||
override def dateFromIs(dateFrom: ZonedDateTime): String = s"📅 Початкова дата ${formatDate(dateFrom, locale)}"
|
||||
|
||||
@@ -221,13 +221,6 @@ object Ua extends Lang {
|
||||
override def upcomingVisitsHeader(page: Int, pages: Int): String =
|
||||
withPages("<b>➡</b> Зарезервовані візити", page, pages)
|
||||
|
||||
override def bugEntry(bug: Bug, page: Int, index: Int): String =
|
||||
s"""⏱ <b>${formatDateTime(bug.submitted, locale)}</b>
|
||||
|Опис: ${bug.details}
|
||||
|Статус: <b>${if (bug.resolved) "✅ Вирішено" else "🚫 Невирішено"}</b>
|
||||
|
|
||||
|""".stripMargin
|
||||
|
||||
override def bugsHeader(page: Int, pages: Int): String =
|
||||
withPages("<b>➡</b> Створені баги", page, pages)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.lbs.server.repository
|
||||
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
import com.lbs.server.repository.model.{Bug, CityHistory, ClinicHistory, Credentials, DoctorHistory, JLong, Monitoring, ServiceHistory, Settings, Source, SystemUser}
|
||||
import com.lbs.server.repository.model.{CityHistory, ClinicHistory, Credentials, DoctorHistory, JLong, Monitoring, ServiceHistory, Settings, Source, SystemUser}
|
||||
import javax.persistence.EntityManager
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Repository
|
||||
@@ -71,14 +71,6 @@ class DataRepository(@Autowired em: EntityManager) {
|
||||
.getResultList.asScala.headOption
|
||||
}
|
||||
|
||||
def getBugs(userId: Long): Seq[Bug] = {
|
||||
em.createQuery(
|
||||
"""select bug from Bug bug where bug.userId = :userId order by bug.submitted desc""".stripMargin, classOf[Bug])
|
||||
.setParameter("userId", userId)
|
||||
.setMaxResults(50)
|
||||
.getResultList.asScala
|
||||
}
|
||||
|
||||
def getActiveMonitorings: Seq[Monitoring] = {
|
||||
em.createQuery(
|
||||
"""select monitoring from Monitoring monitoring where monitoring.active = true""".stripMargin, classOf[Monitoring])
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
|
||||
package com.lbs.server.repository.model
|
||||
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
import javax.persistence.{Access, AccessType, Column, Entity}
|
||||
|
||||
import scala.beans.BeanProperty
|
||||
|
||||
@Entity
|
||||
@Access(AccessType.FIELD)
|
||||
class Bug extends RecordId {
|
||||
@BeanProperty
|
||||
@Column(name = "user_id", nullable = false)
|
||||
var userId: JLong = _
|
||||
|
||||
@BeanProperty
|
||||
@Column(name = "source_system_id", nullable = false)
|
||||
var sourceSystemId: JLong = _
|
||||
|
||||
@BeanProperty
|
||||
@Column(nullable = false)
|
||||
var details: String = _
|
||||
|
||||
@BeanProperty
|
||||
@Column(nullable = false)
|
||||
var resolved: Boolean = false
|
||||
|
||||
@BeanProperty
|
||||
@Column(nullable = false)
|
||||
var submitted: ZonedDateTime = ZonedDateTime.now()
|
||||
}
|
||||
|
||||
object Bug {
|
||||
def apply(userId: Long, sourceSystemId: Long, details: String, resolved: Boolean = false, submitted: ZonedDateTime = ZonedDateTime.now()): Bug = {
|
||||
val bug = new Bug
|
||||
bug.userId = userId
|
||||
bug.sourceSystemId = sourceSystemId
|
||||
bug.details = details
|
||||
bug.resolved = resolved
|
||||
bug.submitted = submitted
|
||||
bug
|
||||
}
|
||||
}
|
||||
@@ -39,15 +39,6 @@ class DataService {
|
||||
dataRepository.findCredentials(accountId)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
def submitBug(userId: Long, sourceSystemId: Long, details: String): Option[Long] = {
|
||||
dataRepository.saveEntity(Bug(userId, sourceSystemId, details)).recordId
|
||||
}
|
||||
|
||||
def getBugs(chatId: Long): Seq[Bug] = {
|
||||
dataRepository.getBugs(chatId)
|
||||
}
|
||||
|
||||
@Transactional
|
||||
def saveMonitoring(monitoring: Monitoring): Monitoring = {
|
||||
dataRepository.saveEntity(monitoring)
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.lbs.server.repository
|
||||
|
||||
import java.time.ZonedDateTime
|
||||
|
||||
import com.lbs.server.repository.model.{Bug, CityHistory, ClinicHistory, Credentials, DoctorHistory, ServiceHistory}
|
||||
import com.lbs.server.repository.model.{CityHistory, ClinicHistory, Credentials, DoctorHistory, ServiceHistory}
|
||||
import javax.persistence.EntityManager
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
@@ -100,16 +100,4 @@ class DataRepositorySpec {
|
||||
val found = dataRepository.getUserCredentials(1L)
|
||||
assertThat(found).isEqualTo(Seq(credentials))
|
||||
}
|
||||
|
||||
@Test
|
||||
def whenGetBugs_thenReturnABug(): Unit = {
|
||||
val bug1 = Bug(1L, 1L, "bug1", resolved = false, ZonedDateTime.now())
|
||||
val bug2 = Bug(1L, 2L, "bug2", resolved = false, ZonedDateTime.now())
|
||||
em.persist(bug1)
|
||||
em.persist(bug2)
|
||||
em.flush()
|
||||
|
||||
val found = dataRepository.getBugs(1L)
|
||||
assertThat(found).isEqualTo(Seq(bug2, bug1))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user