Browse Source
The trait is implemented by TransactionPostgresDataHandler and TransactionPostgresDataHandler. This is a piece for creating endpoints interacting with transactions from the database instead of the xsn service.prometheus-integration
Alexis Hernandez
7 years ago
4 changed files with 54 additions and 6 deletions
@ -0,0 +1,17 @@ |
|||||
|
package com.xsn.explorer.data |
||||
|
|
||||
|
import com.alexitc.playsonify.core.ApplicationResult |
||||
|
import com.xsn.explorer.models.{Blockhash, Transaction, TransactionId} |
||||
|
|
||||
|
import scala.language.higherKinds |
||||
|
|
||||
|
trait TransactionDataHandler[F[_]] { |
||||
|
|
||||
|
def upsert(transaction: Transaction): F[Transaction] |
||||
|
|
||||
|
def delete(transactionId: TransactionId): F[Transaction] |
||||
|
|
||||
|
def deleteBy(blockhash: Blockhash): F[List[Transaction]] |
||||
|
} |
||||
|
|
||||
|
trait TransactionBlockingDataHandler extends TransactionDataHandler[ApplicationResult] |
@ -0,0 +1,28 @@ |
|||||
|
package com.xsn.explorer.data.async |
||||
|
|
||||
|
import javax.inject.Inject |
||||
|
|
||||
|
import com.alexitc.playsonify.core.FutureApplicationResult |
||||
|
import com.xsn.explorer.data.{TransactionBlockingDataHandler, TransactionDataHandler} |
||||
|
import com.xsn.explorer.executors.DatabaseExecutionContext |
||||
|
import com.xsn.explorer.models.{Blockhash, Transaction, TransactionId} |
||||
|
|
||||
|
import scala.concurrent.Future |
||||
|
|
||||
|
class TransactionFutureDataHandler @Inject() ( |
||||
|
blockingDataHandler: TransactionBlockingDataHandler)( |
||||
|
implicit ec: DatabaseExecutionContext) |
||||
|
extends TransactionDataHandler[FutureApplicationResult] { |
||||
|
|
||||
|
override def upsert(transaction: Transaction): FutureApplicationResult[Transaction] = Future { |
||||
|
blockingDataHandler.upsert(transaction) |
||||
|
} |
||||
|
|
||||
|
override def delete(transactionId: TransactionId): FutureApplicationResult[Transaction] = Future { |
||||
|
blockingDataHandler.delete(transactionId) |
||||
|
} |
||||
|
|
||||
|
override def deleteBy(blockhash: Blockhash): FutureApplicationResult[List[Transaction]] = Future { |
||||
|
blockingDataHandler.deleteBy(blockhash) |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue