in src/main/scala/managehelpcontentpublisher/PathAndContent.scala [20:34]
private def removeFromTopics(
publishingOps: PublishingOps
)(article: Article, topics: Seq[ArticleTopic]): Either[Failure, Seq[PathAndContent]] =
topics.map(removeFromTopic(publishingOps)(article)).sequence.map(_.flatten)
private def removeFromTopic(
publishingOps: PublishingOps
)(article: Article)(articleTopic: ArticleTopic): Either[Failure, Option[PathAndContent]] =
for {
oldTopicJson <- publishingOps.fetchTopicByPath(articleTopic.path)
oldTopic <- oldTopicJson.map(readTopic).sequence
newTopicJson <- oldTopic.map(Topic.removeFromTopic(article)).map(writeTopic).sequence
newTopic <- newTopicJson
.map(content => publishingOps.storeTopic(PathAndContent(articleTopic.path, content))).sequence
} yield newTopic