Alexis Hernandez
6 years ago
6 changed files with 98 additions and 1 deletions
@ -0,0 +1,14 @@ |
|||||
|
package com.xsn.explorer.data |
||||
|
|
||||
|
import com.alexitc.playsonify.core.ApplicationResult |
||||
|
import com.xsn.explorer.models.TPoSContract |
||||
|
import com.xsn.explorer.models.values.Address |
||||
|
|
||||
|
import scala.language.higherKinds |
||||
|
|
||||
|
trait TPoSContractDataHandler[F[_]] { |
||||
|
|
||||
|
def getBy(address: Address): F[List[TPoSContract]] |
||||
|
} |
||||
|
|
||||
|
trait TPoSContractBlockingDataHandler extends TPoSContractDataHandler[ApplicationResult] |
@ -0,0 +1,22 @@ |
|||||
|
package com.xsn.explorer.data.anorm |
||||
|
|
||||
|
import com.alexitc.playsonify.core.ApplicationResult |
||||
|
import com.xsn.explorer.data.TPoSContractBlockingDataHandler |
||||
|
import com.xsn.explorer.data.anorm.dao.TPoSContractDAO |
||||
|
import com.xsn.explorer.models.TPoSContract |
||||
|
import com.xsn.explorer.models.values.Address |
||||
|
import javax.inject.Inject |
||||
|
import org.scalactic.Good |
||||
|
import play.api.db.Database |
||||
|
|
||||
|
class TPoSContractPostgresDataHandler @Inject() ( |
||||
|
override val database: Database, |
||||
|
tposContractDAO: TPoSContractDAO) |
||||
|
extends TPoSContractBlockingDataHandler |
||||
|
with AnormPostgresDataHandler { |
||||
|
|
||||
|
def getBy(address: Address): ApplicationResult[List[TPoSContract]] = withConnection { implicit conn => |
||||
|
val result = tposContractDAO.getBy(address) |
||||
|
Good(result) |
||||
|
} |
||||
|
} |
@ -0,0 +1,20 @@ |
|||||
|
package com.xsn.explorer.data.async |
||||
|
|
||||
|
import com.alexitc.playsonify.core.FutureApplicationResult |
||||
|
import com.xsn.explorer.data.{TPoSContractBlockingDataHandler, TPoSContractDataHandler} |
||||
|
import com.xsn.explorer.executors.DatabaseExecutionContext |
||||
|
import com.xsn.explorer.models.TPoSContract |
||||
|
import com.xsn.explorer.models.values.Address |
||||
|
import javax.inject.Inject |
||||
|
|
||||
|
import scala.concurrent.Future |
||||
|
|
||||
|
class TPoSContractFutureDataHandler @Inject() ( |
||||
|
blockingDataHandler: TPoSContractBlockingDataHandler)( |
||||
|
implicit ec: DatabaseExecutionContext) |
||||
|
extends TPoSContractDataHandler[FutureApplicationResult] { |
||||
|
|
||||
|
override def getBy(address: Address): FutureApplicationResult[List[TPoSContract]] = Future { |
||||
|
blockingDataHandler.getBy(address) |
||||
|
} |
||||
|
} |
@ -0,0 +1,27 @@ |
|||||
|
package com.xsn.explorer.data |
||||
|
|
||||
|
import com.xsn.explorer.data.anorm.TPoSContractPostgresDataHandler |
||||
|
import com.xsn.explorer.data.anorm.dao.TPoSContractDAO |
||||
|
import com.xsn.explorer.data.common.PostgresDataHandlerSpec |
||||
|
import com.xsn.explorer.helpers.DataGenerator |
||||
|
import com.xsn.explorer.models.TPoSContract |
||||
|
|
||||
|
class TPoSContractPostgresDataHandlerSpec extends PostgresDataHandlerSpec { |
||||
|
|
||||
|
val dao = new TPoSContractDAO |
||||
|
lazy val dataHandler = new TPoSContractPostgresDataHandler(database, dao) |
||||
|
|
||||
|
"getBy" should { |
||||
|
"return the contracts matching the owner or the merchant address" in { |
||||
|
val owner = DataGenerator.randomAddress |
||||
|
val merchant = DataGenerator.randomAddress |
||||
|
pending |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private def create(contract: TPoSContract): Unit = { |
||||
|
val _ = database.withConnection { implicit conn => |
||||
|
dao.create(contract) |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue