Skip to content

Commit

Permalink
refactor: clean up redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jul 11, 2024
1 parent 394fcd2 commit 2af3db7
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}

/**
Expand Down

0 comments on commit 2af3db7

Please sign in to comment.