Skip to content

Commit

Permalink
Use Transactors read/write with Cats Effect in the Jira plugin (#4333)
Browse files Browse the repository at this point in the history
* Use Transactors read/write with Cats Effect

---------

Co-authored-by: Simon Dumas <simon.dumas@epfl.ch>
  • Loading branch information
imsdu and Simon Dumas authored Oct 5, 2023
1 parent d7fdcd5 commit bcdeee2
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ch.epfl.bluebrain.nexus.delta.plugins.jira

import cats.effect.{Clock, IO}
import ch.epfl.bluebrain.nexus.delta.kernel.effect.migration._
import ch.epfl.bluebrain.nexus.delta.kernel.utils.IOInstant
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors
import ch.epfl.bluebrain.nexus.delta.sourcing.implicits._
Expand Down Expand Up @@ -43,12 +42,10 @@ object TokenStore {
def apply(xas: Transactors)(implicit clock: Clock[IO]): TokenStore = {
new TokenStore {
override def get(user: Identity.User): IO[Option[OAuthToken]] =
toCatsIO(
sql"SELECT token_value FROM jira_tokens WHERE realm = ${user.realm.value} and subject = ${user.subject}"
.query[Json]
.option
.transact(xas.read)
)
sql"SELECT token_value FROM jira_tokens WHERE realm = ${user.realm.value} and subject = ${user.subject}"
.query[Json]
.option
.transact(xas.readCE)
.flatMap {
case Some(token) =>
IO.fromEither(token.as[OAuthToken]).map(Some(_))
Expand All @@ -60,7 +57,7 @@ object TokenStore {
sql""" INSERT INTO jira_tokens(realm, subject, instant, token_value)
| VALUES(${user.realm.value}, ${user.subject}, $now, ${oauthToken.asJson})
| ON CONFLICT (realm, subject) DO UPDATE SET instant = EXCLUDED.instant, token_value = EXCLUDED.token_value
""".stripMargin.update.run.transact(xas.write).void
""".stripMargin.update.run.transact(xas.writeCE).void
}
}
}
Expand Down

0 comments on commit bcdeee2

Please sign in to comment.