-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathLive.scala
More file actions
43 lines (36 loc) · 1.64 KB
/
Live.scala
File metadata and controls
43 lines (36 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package io.pager.subscription
import io.pager.client.telegram.ChatId
import io.pager.log.Logger
import io.pager.subscription.Repository.{ Name, Version }
import io.pager.subscription.chat.ChatStorage
import io.pager.subscription.repository.RepositoryVersionStorage
import zio.{ Task, ZIO }
private[subscription] final case class Live(
logger: Logger,
chatStorage: ChatStorage,
repositoryVersionStorage: RepositoryVersionStorage
) extends SubscriptionLogic {
override def subscribe(chatId: ChatId, name: Name): Task[Unit] =
logger.info(s"$chatId subscribed to $name") *>
chatStorage.subscribe(chatId, name) *>
repositoryVersionStorage.addRepository(name)
override def unsubscribe(chatId: ChatId, name: Name): Task[Unit] =
logger.info(s"Chat $chatId unsubscribed from $name") *>
chatStorage.unsubscribe(chatId, name)
override def listSubscriptions(chatId: ChatId): Task[Set[Name]] =
logger.info(s"Chat $chatId requested subscriptions") *>
chatStorage.listSubscriptions(chatId)
override def listRepositories: Task[Map[Name, Option[Version]]] =
logger.info(s"Listing repositories") *>
repositoryVersionStorage.listRepositories
override def listSubscribers(name: Name): Task[Set[ChatId]] =
logger.info(s"Listing repository ${name.value} subscribers") *>
chatStorage.listSubscribers(name)
override def updateVersions(updatedVersions: Map[Name, Version]): Task[Unit] =
ZIO
.foreach(updatedVersions.toList) { case (name, version) =>
logger.info(s"Updating repository ${name.value} version to $version") *>
repositoryVersionStorage.updateVersion(name, version)
}
.unit
}