diff --git a/src/main/scala/net/yoshinorin/qualtet/domains/series/SeriesService.scala b/src/main/scala/net/yoshinorin/qualtet/domains/series/SeriesService.scala index 8c4ed107..e9af9ea3 100644 --- a/src/main/scala/net/yoshinorin/qualtet/domains/series/SeriesService.scala +++ b/src/main/scala/net/yoshinorin/qualtet/domains/series/SeriesService.scala @@ -34,18 +34,15 @@ class SeriesService[F[_]: Monad]( * @return created Series */ def create(data: RequestSeries): IO[Series] = { - this.findByName(data.name).flatMap { - case Some(s: Series) => - for { - _ <- executer.transact(upsertActions(Series(s.id, s.name, data.title, data.description))) - s <- this.findByName(data.name).throwIfNone(NotFound(detail = "series not found")) - } yield s - case None => - for { - _ <- executer.transact(upsertActions(Series(SeriesId(ULID.newULIDString.toLower), data.name, data.title, data.description))) - s <- this.findByName(data.name).throwIfNone(NotFound(detail = "series not found")) - } yield s - } + this + .findByName(data.name) + .flatMap { + case Some(s: Series) => executer.transact(upsertActions(Series(s.id, s.name, data.title, data.description))) + case None => executer.transact(upsertActions(Series(SeriesId(ULID.newULIDString.toLower), data.name, data.title, data.description))) + } + .flatMap { s => + this.findByName(data.name).throwIfNone(NotFound(detail = "series not found")) + } } /**