Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time
package io.pager.subscription
import io.pager.client.telegram.ChatId
import io.pager.logging.Logger
import io.pager.subscription.Repository.{ Name, Version }
import zio.macros.annotation.mockable
import zio.{ RIO, Task, ZIO }
trait SubscriptionLogic {
val subscriptionLogic: SubscriptionLogic.Service[Any]
object SubscriptionLogic {
trait Service[R] {
def subscribe(chatId: ChatId, name: Name): RIO[R, Unit]
def unsubscribe(chatId: ChatId, name: Name): RIO[R, Unit]
def listSubscriptions(chatId: ChatId): RIO[R, Set[Name]]
def listRepositories: RIO[R, Map[Name, Option[Version]]]
def listSubscribers(name: Name): RIO[R, Set[ChatId]]
def updateVersions(updatedVersions: Map[Name, Version]): RIO[R, Unit]
trait Live extends SubscriptionLogic {
def logger: Logger.Service
def chatStorage: ChatStorage.Service[Any]
def repositoryVersionStorage: RepositoryVersionStorage.Service[Any]
override val subscriptionLogic: Service[Any] = new Service[Any] {
override def subscribe(chatId: ChatId, name: Name): Task[Unit] ="$chatId subscribed to $name") *>
chatStorage.subscribe(chatId, name) *>
override def unsubscribe(chatId: ChatId, name: Name): Task[Unit] ="Chat $chatId unsubscribed from $name") *>
chatStorage.unsubscribe(chatId, name)
override def listSubscriptions(chatId: ChatId): Task[Set[Name]] ="Chat $chatId requested subscriptions") *>
override def listRepositories: Task[Map[Name, Option[Version]]] ="Listing repositories") *>
override def listSubscribers(name: Name): Task[Set[ChatId]] ="Listing repository ${name.value} subscribers") *>
override def updateVersions(updatedVersions: Map[Name, Version]): Task[Unit] =
.foreach(updatedVersions) {
case (name, version) =>"Updating repository ${name.value} version to $version") *>
repositoryVersionStorage.updateVersion(name, version)
object Live {
def make(
logger: Logger.Service,
chatStorageService: ChatStorage.Service[Any],
repositoryVersionStorageService: RepositoryVersionStorage.Service[Any]
): SubscriptionLogic.Service[Any] =
new SubscriptionLogic.Live {
override def logger: Logger.Service = Logger.Test
override def chatStorage: ChatStorage.Service[Any] = chatStorageService
override def repositoryVersionStorage: RepositoryVersionStorage.Service[Any] = repositoryVersionStorageService