Skip to content

Commit

Permalink
feat: delete impl
Browse files Browse the repository at this point in the history
  • Loading branch information
patlo-iog committed May 7, 2024
1 parent 07e1573 commit 701783b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import zio.*
import java.net.URI
import java.net.URL
import java.util.UUID
import org.hyperledger.identus.shared.db.Errors.UnexpectedAffectedRow

sealed trait OIDC4VCIssuerMetadataServiceError(
val statusCode: StatusCode,
Expand Down Expand Up @@ -100,10 +101,11 @@ class OIDC4VCIssuerMetadataServiceImpl(repository: OIDC4VCIssuerMetadataReposito
} yield updatedIssuer

override def deleteCredentialIssuer(issuerId: UUID): ZIO[WalletAccessContext, IssuerIdNotFound, Unit] =
for {
_ <- getCredentialIssuer(issuerId)
_ <- repository.deleteIssuer(issuerId)
} yield ()
repository
.deleteIssuer(issuerId)
.catchSomeDefect { case _: UnexpectedAffectedRow =>
ZIO.fail(IssuerIdNotFound(issuerId))
}

override def createCredentialConfiguration(
issuerId: UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ class JdbcOIDC4VCIssuerMetadataRepository(xa: Transactor[ContextAwareTask]) exte
config: CredentialConfiguration
): URIO[WalletAccessContext, Unit] = ???

override def deleteIssuer(issuerId: UUID): URIO[WalletAccessContext, Unit] = ???
override def deleteIssuer(issuerId: UUID): URIO[WalletAccessContext, Unit] = {
val cxnIO = sql"""
| DELETE FROM public.issuer_metadata
| WHERE id = $issuerId
""".stripMargin.update

cxnIO.run
.transactWallet(xa)
.ensureOneAffectedRowOrDie
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import java.util.UUID
trait ContextAware
type ContextAwareTask[T] = Task[T] with ContextAware

object Errors {
final case class UnexpectedAffectedRow(count: Int) extends RuntimeException(s"Unexpected affected row count: $count")
}

object Implicits {

given walletIdGet: Get[WalletId] = Get[UUID].map(WalletId.fromUUID)
Expand Down Expand Up @@ -47,7 +51,7 @@ object Implicits {
extension (ma: RIO[WalletAccessContext, Int]) {
def ensureOneAffectedRowOrDie: URIO[WalletAccessContext, Unit] = ma.flatMap {
case 1 => ZIO.unit
case count => ZIO.fail(RuntimeException(s"Unexpected affected row count: $count"))
case count => ZIO.fail(Errors.UnexpectedAffectedRow(count))
}.orDie
}

Expand Down

0 comments on commit 701783b

Please sign in to comment.