-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: Add the TPoSContractDataHandler
- Loading branch information
Showing
6 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
server/app/com/xsn/explorer/data/TPoSContractDataHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
22 changes: 22 additions & 0 deletions
22
server/app/com/xsn/explorer/data/anorm/TPoSContractPostgresDataHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
server/app/com/xsn/explorer/data/async/TPoSContractFutureDataHandler.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
server/test/com/xsn/explorer/data/TPoSContractPostgresDataHandlerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} | ||
} |