Skip to content

Commit

Permalink
[TRELLO-2880] Creating a website should be transactionnal
Browse files Browse the repository at this point in the history
  • Loading branch information
charlescd committed Jan 28, 2025
1 parent 8bb2140 commit 6656e6c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions app/repositories/website/WebsiteRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class WebsiteRepository(

import dbConfig._

override def validateAndCreate(newWebsite: Website): Future[Website] =
db.run(
table
override def validateAndCreate(newWebsite: Website): Future[Website] = db.run(
(for {
maybeWebsite <- table
.filter(_.host === newWebsite.host)
.filter { website =>
val hasBeenAlreadyIdentifiedByConso =
Expand All @@ -55,10 +55,12 @@ class WebsiteRepository(
}
.result
.headOption
).flatMap {
case Some(website) => Future.successful(website)
case None => create(newWebsite)
}
website <- maybeWebsite match {
case Some(website) => DBIO.successful(website)
case None => table returning table += newWebsite
}
} yield website).transactionally
)

override def searchValidAssociationByHost(host: String): Future[Seq[Website]] =
db.run(
Expand Down

0 comments on commit 6656e6c

Please sign in to comment.