From 2af3db75168f655b07a70b3281a669098937ec6a Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Thu, 11 Jul 2024 21:12:52 +0900 Subject: [PATCH] refactor: clean up redundant code --- .../domains/series/SeriesService.scala | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) 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")) + } } /**